Skip to content

Instantly share code, notes, and snippets.

@wheresalice
Last active June 12, 2020 18:23
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 wheresalice/49109603de1f254210fabeaa1388ab4c to your computer and use it in GitHub Desktop.
Save wheresalice/49109603de1f254210fabeaa1388ab4c to your computer and use it in GitHub Desktop.
A shell function for cloning a git repository into a sensible place. `ezclone <repo url>` or `ezclone golang <repo url>`
function ezclone() {
# assumes cloning from a git@ url...
# clone to git_src by default
repo_base=~/git_src
if [[ "$1" == "golang" ]]; then
repo_base=~/go/src
shift
fi
repo=$1
reponame=$(basename $repo .git)
repodir=$repo_base/$(dirname $(echo $repo | sed 's/.*@//' | sed 's/:/\//'))
if [ -d $repodir/$reponame ]; then
echo "$reponame already exists!"
else
mkdir -p $repodir
cd $repodir
git clone $repo
fi
cd $repodir/$reponame
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment