Created
November 6, 2011 23:15
-
-
Save tsterker/1343759 to your computer and use it in GitHub Desktop.
[sh] checkout private gist by hash
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
# Function and alias for ~/.bashrc to checkout a private gist by hash | |
# TRY IT OUT | |
# checkout this very gist after you copy/pasted this file into your ~/.bashrc | |
# with this terminal command: | |
# gist 1343759 | |
# temp dir for checkouts | |
GIST_DIR=~/gist_tmp | |
function gist_clone_from_hash() { | |
ghash=$1 | |
gurl="[email protected]:$ghash.git" | |
# if ending / is missing, add it | |
if [ ${GIST_DIR: -1} != '/' ]; then | |
GIST_DIR=$GIST_DIR"/" | |
fi | |
# checkout directory | |
codir=$GIST_DIR$ghash | |
# create GIST_DIR if it doesnt exist | |
if [ ! -d $GIST_DIR ]; then | |
mkdir $GIST_DIR | |
fi | |
# remove old version if exists | |
if [ -d $codir ]; then | |
rm -rf $codir | |
fi | |
git clone "$gurl" $codir | |
# go to checkout dir | |
cd $codir | |
} | |
alias gist="gist_clone_from_hash" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment