Skip to content

Instantly share code, notes, and snippets.

@marcopeg
Last active March 8, 2023 16:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcopeg/0ac0ed5fd206a700d980877b87cc3707 to your computer and use it in GitHub Desktop.
Save marcopeg/0ac0ed5fd206a700d980877b87cc3707 to your computer and use it in GitHub Desktop.
Download and executes a remote gitst
#/bin/bash
#
# Download and executes a remote GitHub gist
# it will store a local cache to improve performances
#
# run `./script --update` to flush local cache
#
# -- Custom Settings
GIST_URL="https://gist.github.com/marcopeg/7a05828b9ead397ba8beb5aaea4c7bfb/raw"
# -- Script Settings (you shouldn't touch it)
SCRIPT_NAME=$(basename "${BASH_SOURCE[0]}")
SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$SCRIPT_NAME"
CACHE_FOLDER=~/.remote-gist
CACHE_FILE="$CACHE_FOLDER/"$SCRIPT_NAME"__$(echo $PWD | tr / .)"
if [ ! -d $CACHE_FOLDER ]; then
mkdir $CACHE_FOLDER
fi
# Force update
if [[ "--update" == $1 ]]; then
rm -f $CACHE_FILE
$SCRIPT_PATH ${@:2}
exit 0
fi
# Download the file
if [ ! -f $CACHE_FILE ]; then
echo ""
echo ""
echo "========== RETRIEVE THE SCRIPT ==========="
if [ $(which wget) ] ; then
wget -O $CACHE_FILE $GIST_URL
else
curl -L -o $CACHE_FILE $GIST_URL
fi
chmod +x $CACHE_FILE
echo "=========================================="
echo ""
echo ""
fi
# Execute the command
$CACHE_FILE $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment