Last active
March 7, 2026 21:18
-
-
Save dotysan/6ca3e3000f11d7cbe6f982cc0eff1dd6 to your computer and use it in GitHub Desktop.
Backup all my gists
This file contains hidden or 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 | |
| # | |
| # Backup all my gists. | |
| # | |
| set -o errexit | |
| set -o nounset | |
| set -o pipefail | |
| # set -o xtrace | |
| printf -v TODAY '%(%F)T' | |
| main() { | |
| mkdir --parents "backup.$TODAY"/{public,secret} | |
| cd "backup.$TODAY" | |
| trap 'pkill -P $$' EXIT | |
| local visibility gist_id | |
| while read -r visibility gist_id | |
| do | |
| if [[ -d "$visibility/$gist_id" ]] | |
| then git -C "$visibility/$gist_id" pull --ff-only --verbose | |
| else git clone "git@gist.github.com:$gist_id.git" "$visibility/$gist_id" | |
| fi & | |
| sleep 0.02 | |
| done < <( | |
| gh api --paginate /gists | | |
| jq --raw-output ' | |
| .[] | | |
| [if .public then "public" else "secret" end, .id] | |
| | @tsv' | |
| ) | |
| wait | |
| ~/src/sh/lt.sh ||: | |
| } | |
| time main "$@" | |
| exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment