Created
April 26, 2010 15:01
-
-
Save justjkk/379436 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
#+-----------------------------------------------------------------------------+ | |
#| Title : Bash Script to Download Selected Gists | | |
#| Author : jkk | | |
#| Date : 26-04-2010 | | |
#+-----------------------------------------------------------------------------+ | |
if [ $# -eq 0 ] ; then | |
cat 1>&2 <<USAGE_TEXT | |
$0: missing gist id(s) | |
Usage: $0 gist_id... | |
USAGE_TEXT | |
exit; | |
fi | |
#do the following steps for all gists inputted | |
for gist in $@; do | |
#Using wget command to download the gist as a tar.gz archive from github | |
wget http://gist.github.com/gists/$gist/download 1>/dev/null 2>&1 -O $gist.tar.gz; | |
if [ $? -ne 0 ]; then | |
echo "Error when downloading from http://gist.github.com/gists/$gist/download" | |
continue | |
fi | |
#Extract the file from the tar.gz archive to standard output and redirect to | |
#the contents to a 'c' file of that name | |
tar -zxvf $gist.tar.gz -O 2>/dev/null >$gist.c; #<-- C EXTENSION | |
#Remove the temporary tar.gz archive | |
rm $gist.tar.gz; | |
#Display Message | |
echo "Gist id($gist) successfully downloaded to $gist.c"; #<-- C EXTENSION | |
done | |
<< AUTHOR_NOTES | |
1. This assumes that one gist contains only one file. If multiple files are present in a single gist, they are concatenated to a single file. | |
2. This appends a '.c' extension to the downloaded files. Search using 'C EXTENSION' to find the places where you can change this. | |
AUTHOR_NOTES |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment