Last active
December 16, 2015 15:19
-
-
Save tannerwelsh/5455134 to your computer and use it in GitHub Desktop.
Easily clone gists that you own using SSH instead of HTTP
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/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