Skip to content

Instantly share code, notes, and snippets.

@huksley
Last active December 22, 2021 08:36
Show Gist options
  • Save huksley/7255147 to your computer and use it in GitHub Desktop.
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.
#!/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
@huksley
Copy link
Author

huksley commented Oct 31, 2013

Quick bootstrap:

  1. Fork to your gists

  2. Using your raw gistsync url, execute:

    curl -so - https://gist.githubusercontent.com/huksley/7255147/raw/gistsync.sh | bash -s - USERNAME

  3. Add $HOME/bin to $PATH and relogin

    echo export PATH=$HOME/bin:$PATH >> .bashrc

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

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