Last active
March 8, 2023 16:12
-
-
Save marcopeg/0ac0ed5fd206a700d980877b87cc3707 to your computer and use it in GitHub Desktop.
Download and executes a remote gitst
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
#/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