Last active
February 2, 2019 10:32
-
-
Save Duncaen/08ccb0d406c3aa78574eac3ff1b0b82a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/dash | |
# git-get repo [git clone args...] -- clone repositories like go get | |
err() { printf "%s: %s\n" "$0" "${@}"; exit 1; } | |
url=$1; shift | |
[ -z "$GIT_PATH" ] && err '$GIT_PATH must be set' | |
[ ! -d "$GIT_PATH" ] && | |
err '$GIT_PATH does not exist or is not a directory' | |
case "$url" in | |
*@*:*) repo=${url#*:} ;; | |
http*://*) repo=${url#http*://*/} ;; | |
# default to github? | |
#*/*) repo=$url; set -- "git@github.com:$url" ;; | |
*) err "'$url' doesn't look like a repository" ;; | |
esac | |
repo=${repo%*.git} | |
path="$GIT_PATH/$repo" | |
[ -e "$path" ] && err 'repository already exists' | |
mkdir -p "${path%/*}" || exit | |
git clone "$@" "$url" "$path" || exit | |
printf '%s\n' "$path" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment