Last active
July 21, 2019 15:59
-
-
Save NQNStudios/0d3b8261cff673c9f6fd to your computer and use it in GitHub Desktop.
Manages executable scripts stored in Gists for use on Unix systems.
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 | |
# 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 [email protected]:/${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 |
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 | |
# 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 |
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 | |
# 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