Skip to content

Instantly share code, notes, and snippets.

@paulwratt
Last active May 6, 2020 02:31
Show Gist options
  • Save paulwratt/c8199d1e2162a82d475d7777a67d6f13 to your computer and use it in GitHub Desktop.
Save paulwratt/c8199d1e2162a82d475d7777a67d6f13 to your computer and use it in GitHub Desktop.
List raw urls of a users gist.github files (using: curl grep jq sed )
#!/bin/sh
# 2020-05-06 - paulwratt@github
# ( 'jq' is a command line json tool )
# ( https://stedolan.github.io/jq/tutorial/ )
# https://gist.github.com/paulwratt/c8199d1e2162a82d475d7777a67d6f13
#
if [ "$1" = "" -o "$1" = "--help" ]; then
echo "List raw urls of gist.github files (uses: curl grep jq sed)"
echo "usage: gist-file [--help] | [_username_ [_filename_ | all]]"
echo " _username_ GitHub username"
echo " _filename_ filename of Gist"
echo " all list all Gist file raw urls"
echo ""
echo "examples:"
echo "gist-file paulwratt (list filenames with Gist descriptions)"
echo "gist-file paulwratt all (list all urls of files)"
echo "gist-file paulwratt cross-mint (list all 'cross-mint' urls)"
echo "gist-file paulwratt cross-mint | xargs wget (download files)"
echo "gist-file paulwratt gist-file | xargs wget (download this)"
echo ""
exit
fi
if [ "$2" = "" ]; then
curl -s https://api.github.com/users/$1/gists | jq -M '.[] | { t: .description, f: [.files[].filename] }' | grep -v '{' | grep -v '}' | grep -v '\[' | grep -v '\]' | sed 's/ "t": "//g' | sed 's/",$//g' | sed 's/"$//g' | sed 's/ "//g'
exit
fi
if [ "$2" = "all" ]; then
curl -s https://api.github.com/users/$1/gists | jq -M '.[] | { f: .files[].raw_url }' | grep -v '{' | grep -v '}' | sed 's/ "f": "//g' | sed 's/",$//g' | sed 's/"$//g'
exit
fi
for i in `curl -s https://api.github.com/users/$1/gists | jq -M '.[] | { f: .files[].raw_url }' | grep -v '{' | grep -v '}' | sed 's/ "f": "//g' | sed 's/",$//g' | sed 's/"$//g'`; do
xFILE=`echo "$i" | cut -d \/ --fields=8`
if [ "$xFILE" = "`echo "$xFILE" | grep $2`" ]; then
echo "$i"
fi
done
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment