Skip to content

Instantly share code, notes, and snippets.

@JPDesign
Forked from NQNStudios/install-gist-scripts
Last active April 17, 2017 23:22
Show Gist options
  • Save JPDesign/b895d3bebfef17eead0556e6e7f1d138 to your computer and use it in GitHub Desktop.
Save JPDesign/b895d3bebfef17eead0556e6e7f1d138 to your computer and use it in GitHub Desktop.
Manages executable scripts stored in Gists for use on Unix systems.
#!/bin/bash
# First argument: the ID of the Github Gist to clone from
GIST_ID=${1}
# Clone the gist in our bin directory
cd ~/bin
git clone git@gist.github.com:/${GIST_ID}.git
# symlink all scripts for global execution
for entry in "$GIST_ID"/*
do
SCRIPT_NAME=$entry
ln $SCRIPT_NAME
chmod +x $SCRIPT_NAME
done
#!/bin/bash
# First argument: the ID of the Github Gist to uninstall
GIST_ID=${1}
# Enter the directory where the gist was cloned
cd ~/bin
cd $GIST_ID
# Delete the symlink copy of every script in the gist
SCRIPTS=*
for f in $SCRIPTS
do
rm ../$f # delete symlink
done
# Delete the folder containing the clone of the gist
cd ~/bin
rm -rf $GIST_ID
#!/bin/bash
# First argument: the ID of the Github Gist to pull from
GIST_ID=${1}
# Enter the directory where the gist was cloned
cd ~/bin
cd $GIST_ID
# Stash any local changes
git stash
# Update the clone to the newest version of the gist
git pull
# Loop through every script in the gist, remaking its symlink so an old
# version doesn't run instead.
SCRIPTS=*
for f in $SCRIPTS
do
chmod +x $f
# If the file existed in the previous version, delete its symlink
if [ -f ../$f ];
then
rm ../$f
fi
# Make a new symlink for this script
ln $f ../$f
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment