Thursday, November 29, 2012

shell.function to download all files from any GITHUB GIST URL

a shell utility to download all files part of a GIST url at provided download path

usage e.g. $ ddl-gist https://gist.github.com/4165864 /etc/profile.d/

howTo install
$ curl -L -o /etc/profile.d/ddl-gist.sh https://gist.github.com/4165864

actually, if you had this utlity... the usage example would install the utlity... chicken-egg

# Usage Example: $ ddl-gist 'https://gist.github.com/4137843' ~/Downloads/gists
# save the gist files at that URL in ~/Downloads/gists
##
ddl_gist(){
if [ $# -ne 2 ];
then
echo 'Failed. Syntax: $> ddl-gist GITHUB_GIST_URL DOWNLOAD_PATH'
return
fi
gist_url=$1
download_path=$2
echo '[*] Getting all GIST File URLs from '$gist_url
gists=`curl -ksL -H 'User-Agent: Mozilla/5.0' $gist_url | grep '<a\ .*href=".*/raw/' | sed 's/.*a\ .*href="//' | sed 's/".*//'`
echo '[*] Downloading all files'
for lines in `echo $gists | xargs -L1`;
do
if [ ! -z $lines ];
then
echo $lines
gistfile=`echo $lines | sed 's/.*\///'`
save_as=$download_path"/"$gistfile
echo "Downloading URL: https://gist.github.com"$lines
echo "to "$save_as"....."
wget -c -O $save_as "https://gist.github.com"$lines
fi
done
}
view raw gistfile1.sh hosted with ❤ by GitHub

No comments:

Post a Comment