Skip to content

Instantly share code, notes, and snippets.

@CMarzin
Last active January 9, 2018 10:09
Show Gist options
  • Save CMarzin/0c8fdebdcde21776336b6b897454a2d8 to your computer and use it in GitHub Desktop.
Save CMarzin/0c8fdebdcde21776336b6b897454a2d8 to your computer and use it in GitHub Desktop.
Clone your own repo to anywhere you want in 2 command
#!/bin/bash
URL=$(curl -s 'https://api.github.com/user/repos?sort=pushedaccess_token=YOUR_PERSONNAL_GITHUB_TOKEN' | jq '.[] | .ssh_url' );
URL=${URL[@]//\"/};
clone(){
echo "Git clone: '$@'"
git clone $@
REPO=$@
temp=$(echo "$REPO" | grep -Po '(?<=\/)(.*?)(?=\.)')
echo "Now you can do :"
echo cd $temp
}
title="Select a git repositories"
prompt="Choose a repositorie:"
options=($URL)
echo "$title"
PS3="$prompt "
select opt in "${options[@]}" "Quit"; do
case "$REPLY" in
$(( ${#options[@]}+1 )) ) echo "Goodbye!"; break;;
$REPLY ) echo "You choose $opt";
clone "$opt";
break;;
*) echo "Invalid option. Try another one.";continue;;
esac
done
@CMarzin
Copy link
Author

CMarzin commented Aug 22, 2017

For functionning you need to install jq first :

Little explanation

  • PS3 and REPLY vars can not be renamed. select is hardcoded to use those. All other variables in script (opt, options, prompt, title) can have any names you want, provided you do the adjustments

Make the script executable :

chmod +x script-git.sh

Add permission :

chmod 777 script-git.sh

Launch the script in the directory you choose

Personally I move this tiny script in my root directory

# type cd to go at the root directory
cd 
# then
./script-git.sh

I recommend you to create an alias in your .bashr or .zshrc

# ~/ = root directory where the script is located
alias myRepo="~/./script-git.sh"

Enjoy !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment