Last active
December 22, 2021 08:36
-
-
Save huksley/7255147 to your computer and use it in GitHub Desktop.
Downloads all .sh gists for user (current user if not set), into $HOME/bin folder. This script will overwrite all local changes.
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 | |
# Downloads all .sh gists for user into $HOME/bin. | |
GUSER=`whoami` | |
GUSERN=$1 | |
if [ "$GUSERN" != "" ]; then | |
GUSER=$GUSERN | |
echo $GUSERN > $HOME/.gistuser | |
fi | |
if [ -f $HOME/.gistuser ]; then | |
GUSER=`cat $HOME/.gistuser` | |
fi | |
echo Downloading all shell gists for $GUSER | |
ALL=`curl -s https://api.github.com/users/$GUSER/gists?per_page=100 | grep raw_url | cut -d: -f2- | grep .sh\" | sed -re "s/\"//g;s/,$//g"` | |
if [ "${PIPESTATUS[0]}" != "0" ]; then | |
echo Failed curl -s https://api.github.com/users/$GUSER/gists with status ${PIPESTATUS[0]} | |
exit 1 | |
fi | |
for U in $ALL; do | |
N=`basename $U .sh` | |
echo $N... | |
if [ ! -d $HOME/bin ]; then | |
mkdir $HOME/bin | |
fi | |
curl -s $U | sed -e 's/\r$//g' >$HOME/bin/$N | |
if [ "${PIPESTATUS[0]}" != "0" ]; then | |
echo Failed curl -s $U with status ${PIPESTATUS[0]} | |
exit 1 | |
fi | |
chmod u+x $HOME/bin/$N | |
done | |
ALL=`curl -s https://api.github.com/users/$GUSER/gists?per_page=100 | grep raw_url | cut -d: -f2- | grep .shlink\" | sed -re "s/\"//g;s/,$//g"` | |
for U in $ALL; do | |
LINK=`curl -s -o - $U | sed -e 's/\r$//g'` | |
if [ "${PIPESTATUS[0]}" != "0" ]; then | |
echo Failed curl -s -o - $U with status ${PIPESTATUS[0]} | |
exit 1 | |
fi | |
N=`basename $U .shlink` | |
echo "$N (shlink)..." | |
if [ ! -d $HOME/bin ]; then | |
mkdir $HOME/bin | |
fi | |
curl -s $LINK | sed -e 's/\r$//g' >$HOME/bin/$N | |
if [ "${PIPESTATUS[0]}" != "0" ]; then | |
echo Failed curl -s $LINK with status ${PIPESTATUS[0]} | |
exit 1 | |
fi | |
chmod u+x $HOME/bin/$N | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quick bootstrap:
Fork to your gists
Using your raw gistsync url, execute:
Add $HOME/bin to $PATH and relogin
First time will be running using my gistsync, all other time will be running your gistsync copy.
Gistsync and all your gists will be downloaded to $HOME/bin