Created
November 4, 2020 20:28
-
-
Save pwm/7512d8b1c7c66214159b818612de9fc1 to your computer and use it in GitHub Desktop.
gisto
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 | |
set -euo pipefail | |
cd "$(dirname "${BASH_SOURCE[0]}")" | |
if [ "$#" -ne 1 ]; then | |
echo "Usage: gisto.sh <user>" | |
exit 1 | |
fi | |
#TODO: pagination if more than 100 gists | |
query_url="users/$1/gists?per_page=100&page=1" | |
needs() { | |
[[ "$(command -v "$1")" ]] || { echo "$1 is not installed" 1>&2; exit 1; } | |
} | |
needs git | |
needs hub | |
needs jq | |
gists=$(hub api "$query_url" | jq -rc '.[] | {"id":.id, "url":.git_pull_url, "desc":(.description | tostring | sub("null"; "") | gsub("[/ ]"; "_") | ascii_downcase)}') | |
for gist in $gists; do | |
gist_id=$(echo "$gist" | jq -r '.id') | |
gist_url=$(echo "$gist" | jq -r '.url') | |
gist_desc=$(echo "$gist" | jq -r '.desc') | |
git clone "$gist_url" "${gist_desc:-$gist_id}" || true | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment