Skip to content

Instantly share code, notes, and snippets.

@wheresalice
Last active Jun 12, 2020
Embed
What would you like to do?
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