Skip to content

Instantly share code, notes, and snippets.

@johanvergeer
Last active December 12, 2021 18:20
Show Gist options
  • Save johanvergeer/96e9c5be11f91baa6bd22e6435368e9d to your computer and use it in GitHub Desktop.
Save johanvergeer/96e9c5be11f91baa6bd22e6435368e9d 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
@johanvergeer
Copy link
Author

johanvergeer commented Mar 3, 2018

This snippet was created based on the tutorial by on Nat Quayle Nelson on YouTube https://www.youtube.com/watch?v=A3HEald6-1Q

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