Last active
December 12, 2021 18:20
-
-
Save johanvergeer/96e9c5be11f91baa6bd22e6435368e9d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/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 [email protected]:${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
This snippet was created based on the tutorial by on Nat Quayle Nelson on YouTube https://www.youtube.com/watch?v=A3HEald6-1Q