Skip to content

Instantly share code, notes, and snippets.

@knbknb
Last active May 23, 2022 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knbknb/0ce25b41c0a58a59f0fe22be2a19e38b to your computer and use it in GitHub Desktop.
Save knbknb/0ce25b41c0a58a59f0fe22be2a19e38b to your computer and use it in GitHub Desktop.
GET date, url, filename, description of all my github gists, ordered by crdate DESC
#!/bin/sh
# knb 2019,2022
# get date, url, filename, description of all my github gists, ordered by crdate DESC
#GITHUB_PAT=5b01b116a34967ff0afce4d45205f907d45501c9
GITHUB_PAT=
if [ -z "$1" ]
then
user=knbknb
else
user=$1
fi
url="https://$GITHUB_PAT:x-oauth-basic@api.github.com/users/$user/gists"
# -k = --insecure (TLS-wise)
#echo "curl -sL -k -I \"$url?state=all&per_page=10\" >&2"
head_request_result=$(curl -sL -k -I "$url?state=all&per_page=10")
http_status=$(echo "$head_request_result" | grep -oP "(?>HTTP/2\s*)\d+")
if [ "$http_status" != "HTTP/2 200" ]
then
echo "ERROR: HTTP Status: $http_status"
exit 1
fi
total_pages=$(echo "$head_request_result" | awk -F'[&=<>]' '{for(i=1;i<=NF;i++) if($i ~ /^page$/) {kk=$(i+1)}} END{print kk}');
echo "total pages of gists: $total_pages" >&2
echo ""
echo "crdate\turl\tdescription"
for i in $( seq 1 $total_pages); do
curl -k $url?state=all\&per_page=10\&page=$i 2>/dev/null | \
jq -L$HOME/.jq -r '.[] | (.created_at | sub("T.*";"")) as $date | select($date) | [$date, .html_url, (.files | keys_unsorted)[0], .description] | @tsv'
done
@knbknb
Copy link
Author

knbknb commented Dec 10, 2019

interesting users

knbknb
ecampidoglio - git expert

@knbknb
Copy link
Author

knbknb commented Dec 10, 2019

on Linux his works as a Powershell pipeline!

~/bin/github_my_gists.sh karpathy | ConvertFrom-Csv -Delimiter `t -header 'date', 'url', 'filename', 'description' | out-gridview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment