Skip to content

Instantly share code, notes, and snippets.

@pwm
Created November 4, 2020 20:28
Show Gist options
  • Save pwm/7512d8b1c7c66214159b818612de9fc1 to your computer and use it in GitHub Desktop.
Save pwm/7512d8b1c7c66214159b818612de9fc1 to your computer and use it in GitHub Desktop.
gisto
#!/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