Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save allanpedroni/879b8bb2830dacf0dcadc7973d50cd73 to your computer and use it in GitHub Desktop.
Save allanpedroni/879b8bb2830dacf0dcadc7973d50cd73 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
GIST_ID=${1}
# Check if the GIST_ID param has a value
if [ -z "$GIST_ID" ];
then
echo 'GIST_ID is a required parameter';
else
# Move to the $HOME/bin directory where the gists will be stored
cd ~/bin
# Control will enter here if $DIRECTORY exists.
if [ -d ${GIST_ID} ]; then
echo 'The gist already exists and will be replaced'
# Remove the existing symlinks
for SCRIPT_NAME in ${GIST_ID}/*
do
echo 'Removing current symlink '`(basename ${SCRIPT_NAME})`
rm `(basename ${SCRIPT_NAME})`;
done
# Remove the existing gist directory
echo 'Removing current directory ' ${GIST_ID}
rm -rf ${GIST_ID}
fi
# Clone the gist
echo 'Cloning the gist'
git clone git@gist.github.com:${GIST_ID}.git
# Create a symlink in the bin directory to each file in the gist
# This way each script can be called as an executable
for SCRIPT_NAME in ${GIST_ID}/*
do
echo 'Creating a symlink for ' ${SCRIPT_NAME}
ln ${SCRIPT_NAME};
# Make the files inside the gist executable
chmod +x ${SCRIPT_NAME}
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment