Skip to content

Instantly share code, notes, and snippets.

@hlorand
Created March 1, 2023 22:42
Show Gist options
  • Save hlorand/859beca8977bd063989d681b06cf0a15 to your computer and use it in GitHub Desktop.
Save hlorand/859beca8977bd063989d681b06cf0a15 to your computer and use it in GitHub Desktop.
Clone every GitHub Gists into separate folders
#!/bin/bash
##################################
# Clone every GitHub Gist
# Requirement: The GitHub CLI
# sudo apt install gh
##################################
mkdir gists
cd gists
# function that creates a slug from a text, for example slugify "hello world" --> hello-world
slugify(){ echo "$1" | iconv -t ascii//TRANSLIT | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z; }
# initializes a counter and lists every gist in reverse order, then clones all of them in a directory named COUNTER-gist-description
cnt=0; gh gist list --limit 1000 | cut -f1,2 | tac | while read id name; do ((cnt++)); gh gist clone $id $cnt-`slugify "$name"`; done
# the result:
# 1-my-first-gist/
# 2-my-second-gist/
# 3-...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment