Skip to content

Instantly share code, notes, and snippets.

@tannerwelsh
Last active December 16, 2015 15:19
Show Gist options
  • 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="[email protected]:$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