Skip to content

Instantly share code, notes, and snippets.

@tito
Created November 17, 2012 14:51
Show Gist options
  • Save tito/4096543 to your computer and use it in GitHub Desktop.
Save tito/4096543 to your computer and use it in GitHub Desktop.
Download and extract a GIST zipfile.
#!/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