-
-
Save tito/4096543 to your computer and use it in GitHub Desktop.
Download and extract a GIST zipfile.
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 | |
GISTS_DIR=~/.gists | |
FILENAME=$1.tar.gz | |
if [ "X$1" == "X" ]; then | |
echo "Usage: gist <gistid>" | |
exit 1 | |
fi | |
if [ ! -d $GISTS_DIR ]; then | |
mkdir $GISTS_DIR | |
fi | |
cd $GISTS_DIR | |
if [ -f $FILENAME ]; then | |
rm $1.tar.gz | |
fi | |
echo "> Downloading Gist $1..." | |
curl -s "https://gist.github.com/gists/$1/download" > $1.tar.gz || exit 1 | |
echo "> Untar Gist $1..." | |
tar vxzf $1.tar.gz || exit 1 | |
echo "> Entering in the directory" | |
DIRECTORY=$(tar tzfv $1.tar.gz | awk '{print $6}' | head -n1) | |
cd $DIRECTORY | |
echo "> Gist extracted at" $(pwd) | |
echo "> Type 'exit' or Control+D for exiting the env." | |
echo -n "> Available files: " | |
ls | |
echo | |
$SHELL | |
cd .. | |
if [ -d $DIRECTORY ]; then | |
rm -rf $DIRECTORY | |
echo "> Gist $1 directory deleted" | |
fi | |
if [ -f $FILENAME ]; then | |
rm -f $FILENAME | |
echo "> Gist $1 archive deleted" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment