Skip to content

Instantly share code, notes, and snippets.

@loganlinn
Last active April 28, 2020 04:35
Show Gist options
  • Save loganlinn/5b506c9c708859ad99a766842dbce9a8 to your computer and use it in GitHub Desktop.
Save loganlinn/5b506c9c708859ad99a766842dbce9a8 to your computer and use it in GitHub Desktop.
# @description clones git repository (including submodules) and changes working
# directory to it. If `directory` not specified, uses $PROJECTS.
# and if that's not set, fallsback to current directory.
#
# @example gclone [email protected]:loganlinn/blog.git
# @example gclone loganlinn/blog
function gclone {
emulate -L zsh
if [[ "$#" -eq 0 ]]; then
echo "Usage: $0 <repository> [<directory>]" >&2
return 1
fi
local repository="$1"
local directory="$2"
if [[ -z "$directory" ]]; then
directory="${GCLONE_HOME:-${PROJECTS:-$(pwd)}}/${repository:t:r}"
fi
hub clone --recurse-submodules -- "$repository" "$directory"
cd "$directory"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment