Skip to content

Instantly share code, notes, and snippets.

@chenchun
Last active July 31, 2024 05:30
Show Gist options
  • Save chenchun/c317b7760ea5a289ebc4c8e36fcf9145 to your computer and use it in GitHub Desktop.
Save chenchun/c317b7760ea5a289ebc4c8e36fcf9145 to your computer and use it in GitHub Desktop.
clone all gists and better search them with your own tools #github #gists
#! /bin/bash
set -x
set -e
# generate your token from https://github.com/settings/tokens and save it into gist-token.txt
token=$(cat gist-token.txt)
function cloneOrPull() {
page=$1
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $token" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/gists?per_page=100&page=$page" > gists-${page}.json
jq -c -r '.[]' gists-${page}.json | while read gist; do
id=$(echo $gist | jq -r '.id')
if [ -d "$id" ]; then
cd $id; git pull > /dev/null 2>&1; cd ..
else
git clone $(echo $gist | jq -r '.git_pull_url') > /dev/null 2>&1
fi
done
jq length gists-${page}.json
}
page=1
count=0
while true; do
length=$(cloneOrPull $page)
count=$(($count + $length))
if [ $length -lt 100 ]; then
break
fi
page=$(($page + 1))
done
echo total $count gists
@erbanku
Copy link

erbanku commented Jul 30, 2024

Works, thanks.

@erbanku
Copy link

erbanku commented Jul 30, 2024

To search your gist content: https://gist.github.com/search?q=%s+%40erbanku&ref=searchresults
You can add this to your browser's custom search engine list to navigate more fast.
image

@chenchun
Copy link
Author

@erbanku thanks for sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment