Created
March 1, 2023 22:42
-
-
Save hlorand/859beca8977bd063989d681b06cf0a15 to your computer and use it in GitHub Desktop.
Clone every GitHub Gists into separate folders
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
#!/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