Last active
September 11, 2018 08:29
-
-
Save Chandru-B/7807182670c59fe08965463baf8b4189 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
programname=$0 | |
authtoken=$1 | |
username=$2 | |
option=$3 | |
function usage { | |
echo "usage: $programname [authtoken] [username] [-a|-n]" | |
exit 1 | |
} | |
if [ $# -lt 2 ] | |
then | |
usage | |
fi | |
if [ -z $option ]; then | |
option="-n" | |
fi | |
response=$(curl -s -H "Authorization: token $authtoken" https://api.github.com/users/$username/gists) | |
last_created_at="${username}_last_created_at.txt" | |
if [ ! -f $last_created_at ]; then | |
echo $response | jq '.[].created_at' | sort -n -k 1 | tail -n 1 > "$last_created_at" | |
echo $response | jq '.[].files[].raw_url' | xargs curl | |
elif [ "$option" == "-n" ]; then | |
last_created_dt=$(cat $last_created_at | sed -e 's/^"//' -e 's/"$//') | |
newgists=$(echo $response | jq --arg ld $last_created_dt '.[] | select(.created_at | . > $ld) | .files[].raw_url') | |
if [ ! -z $newgists ]; then | |
echo $newgists | xargs curl | |
echo $response | jq '.[].created_at' | sort -n -k 1 | tail -n 1 > "$last_created_at" | |
else | |
echo -e "No new gist published by $username since $last_created_dt.\nTo get all public gists \n\nusage: $programname [authtoken] [username] -a" | |
fi | |
elif [ "$option" == "-a" ]; then | |
echo $response | jq '.[].files[].raw_url' | xargs curl | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
get the latest published gist for any user.
Please install jq before running the script