This Shell Script file enable us to clone (or fork) a repository from github without using the git syntax.
Disclaimer: please do the quick setup before using this code for the first time.
Run the command ./cloneRepo.sh
or sh cloneRepo.sh
to start the program.
Once the code is running, type the name of the repository you want to clone and press the "enter" key. That's it, done. It is really that simple.
They are some extra features to boost the experience:
However, you can change some settings before cloning the repository (typing settings
when asked for the name of the repository):
Furthermore, you can select the repository from your account by using the option list
instead of typing it manually (specially usefull when you don't remember the exact name). Once selected, this screen will appear:
In order to select it, use the arrows UP and DOWN to navigate and the ENTER key to select it.
Note: If you want to fork the selected repository, just add the fork argument like this example:
./cloneRepo.sh fork
In order to boost this code, please consider following this steps:
-
Constants declaration:
- Add your Git username.
- Add the default directory to store the repository.
This can be accomplished modifying the following code:
# Constants: u="Jkutkut"; # Default user name fullDirectory=~/github/; # Default dir to store the repository
Note: The protocol used to do the cloning (e.i. SSH) can also be changed using the variable "protocol".
-
List mode:
Please install jq, a simple Command-line JSON processor, which will come in handy. This can be accomplished by the use of the command:sudo apt install jq
We have different ways to get the repositories:
- Auto: This option connects directly to github and gets the names of the repositories available automatically and dynamically. This way, a simple selection menu will appear where you can select the repository you want to clone.
There are two situations here: Getting the repositories from our account and getting them from other's. To accomplish the first one, using a Github's Personal access token will provide us also with the private repositories from our account (use this link to get it). This way, in both cases we can get all the repositories easily.
To enable this feature, use the line at the following command (/home/$USER/github/.variables/cloneRepoData.sh) to store the token in a file using the syntax:
#!/bin/sh
export TOKEN="XXXX"
If you prefer, you can overwrite "$TOKEN" with the token (use this feature at your own risk). The code can be found here:
if [ $u = $defUser ]; then curl -H "Authorization: token $TOKEN" -s "https://api.github.com/search/repositories?q=user:$u&type:all&per_page=100" | jq '.items|.[]|.full_name' | cut -d'/' -f 2 | sed 's/.$//' | sort; else curl -s "https://api.github.com/search/repositories?q=user:$u&type:all&per_page=100" | jq '.items|.[]|.full_name' | cut -d'/' -f 2 | sed 's/.$//' | sort; fi
Note: In order to skip adding the token, just keep the lines under the else statement.
- Manual: This option uses as repository names the lines of a file given. This features enables an easy setup for different Git servers. To activate this feature, modify the name of the file in the following line (In this example, the name used is repositorios.txt):
cp repositorios.txt temp.txt; # Option 2
- Auto: This option connects directly to github and gets the names of the repositories available automatically and dynamically. This way, a simple selection menu will appear where you can select the repository you want to clone.
-
Option to fork:
This code can fork the selected repository by the use of the hub command. Please installing using:sudo apt install hub