Skip to content

Instantly share code, notes, and snippets.

@christianscott
Created June 5, 2019 00:55
Show Gist options
  • Save christianscott/5ef2d2388abc7e0c0e8291293d082f03 to your computer and use it in GitHub Desktop.
Save christianscott/5ef2d2388abc7e0c0e8291293d082f03 to your computer and use it in GitHub Desktop.
Clone a repo from github into a GOPATH-style working directory
#!/usr/bin/env bash
set -e
main() {
local repo_path;
repo_path="$1"
if ! [[ $repo_path =~ ^.+/.+$ ]]; then
echo "invalid repo path. git-get expects a path of the form 'user/repo'"
exit 1
fi
local user;
local repo;
user=$(dirname $repo_path)
repo=$(basename $repo_path)
local work_dir
work_dir="${GIT_GET_WORK_DIR:-$HOME/Code/github.com/}${user}"
mkdir -p "${work_dir}"
cd "${work_dir}"
if [[ -d "${repo}" ]]; then
echo "repo already exists at ~${work_dir#$HOME}/${repo}"
exit 1
fi
git clone "[email protected]:$repo_path"
echo "Cloned package to ~${work_dir#$HOME}/${repo}"
}
main $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment