Skip to content

Instantly share code, notes, and snippets.

@dotysan
Last active March 7, 2026 21:18
Show Gist options
  • Select an option

  • Save dotysan/6ca3e3000f11d7cbe6f982cc0eff1dd6 to your computer and use it in GitHub Desktop.

Select an option

Save dotysan/6ca3e3000f11d7cbe6f982cc0eff1dd6 to your computer and use it in GitHub Desktop.
Backup all my gists
#! /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