Skip to content

Instantly share code, notes, and snippets.

@tannerwelsh
Last active December 16, 2015 15:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tannerwelsh/5455134 to your computer and use it in GitHub Desktop.
Save tannerwelsh/5455134 to your computer and use it in GitHub Desktop.
Easily clone gists that you own using SSH instead of HTTP
#!/bin/bash
# <<< gistclone >>>
#
# Why clone gists with HTTP when you can use SSH?
#
# Just put this somewhere in your PATH, make it executable, and you're good to go.
#
# Usage:
# $ gistclone <gist_url> [<directory>]
#
# Examples:
# $ gistclone https://gist.github.com/openspectrum/5455134 my_gist
# OR
# $ gistclone https://gist.github.com/5455134.git my_gist
gist_url=$1
gist_dir=$2
# Extract sha from url
if [[ $gist_url = *gist* ]]
then
sha=${gist_url##*/}
sha=${sha%.git}
else
echo 'Unable to parse gist url'
exit 1
fi
# Convert sha to git uri
git_uri="git@github.com:$sha.git"
# Clone the gist into the directory
exec git clone $git_uri $gist_dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment