Skip to content

Instantly share code, notes, and snippets.

@anselm94
Created January 3, 2020 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anselm94/a4ecac57538c09389603caad5b014ab1 to your computer and use it in GitHub Desktop.
Save anselm94/a4ecac57538c09389603caad5b014ab1 to your computer and use it in GitHub Desktop.
Simple Bash script file to quickly Git clone and open VS Code

Git Cloner

A simple git cloner script, which clones any Git repository to your set Projects folder and opens VS Code to quickly get started editing.

Steps

  • Copy the above script and paste it in a file named git-clone
  • Adjust PROJECTS_LOCATION variable to your Projects folder
  • Assign necessary permissions to execute
    chmod +x git-clone
    
  • Add necessary paths to $PATH environment variable
  • Adjust the path for VS Code (Assumed code command maps to VS Code)
  • Logout & login

Anytime, type git-clone in terminal and start cloning. Once cloned, press Y to open in VS Code

echo "#############################"
echo " Git Cloner "
echo "#############################"
PROJECTS_LOCATION=$HOME/Projects/Git
giturl=$1
if [ -z "$giturl" ]; then
read -p "Enter Github/Git URL (default:$giturl): " giturl
fi
gitname=$(basename -s .git $giturl)
read -p "Enter directory path (default:$gitname):" newname
if [ -n "$newname" ]; then
foldername=$newname
else
foldername=$gitname
fi
gitloc="${PROJECTS_LOCATION}/${foldername}"
git clone $giturl $gitloc
echo "Successfully cloned $gitname in $gitloc"
read -p "Do you want to open in VS Code? (Y/N): " choice
case $choice in
y|Y ) code $gitloc;;
* ) exit
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment