Skip to content

Instantly share code, notes, and snippets.

@henderea
Last active February 12, 2018 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henderea/98aebdafe6ddb030d1de61d47c4b87ef to your computer and use it in GitHub Desktop.
Save henderea/98aebdafe6ddb030d1de61d47c4b87ef to your computer and use it in GitHub Desktop.
Shell function for installing the scripts
# include this in your .bashrc or .zshrc if you want to enable command output for install_scripts
# INSTALL_SCRIPTS_DEBUG=1
function _install_scripts_debug {
[[ $INSTALL_SCRIPTS_DEBUG -eq 1 ]] && echo $@
}
function install_scripts {
INSTALL_SCRIPTS_VERSION="20"
# define configuration
GIST_USER="henderea"
LIST_URL="https://gist.githubusercontent.com/henderea/48d131bf9d3773c2057a2a171eb7f87d/raw/scripts.txt"
DT="?rand=$(date +%s)"
INSTALL_SCRIPTS_URL="https://gist.githubusercontent.com/henderea/98aebdafe6ddb030d1de61d47c4b87ef/raw/install_scripts.sh"
INSTALL_SCRIPTS_LOC="$HOME/.install_scripts.sh"
# main script
case "$1" in
upgrade)
echo "Downloading latest script"
_install_scripts_debug "> curl -SL --progress-bar $INSTALL_SCRIPTS_URL$DT -o $INSTALL_SCRIPTS_LOC"
curl -SL --progress-bar $INSTALL_SCRIPTS_URL$DT -o $INSTALL_SCRIPTS_LOC
_install_scripts_debug "> install_scripts reload"
install_scripts reload ">"
_install_scripts_debug "> install_scripts version"
install_scripts version
;;
reload)
echo "Reloading install_scripts shell integration"
_install_scripts_debug "$2> source $INSTALL_SCRIPTS_LOC"
source $INSTALL_SCRIPTS_LOC
;;
version)
echo "install_scripts is at version $INSTALL_SCRIPTS_VERSION"
;;
settings)
cat << EOM
INSTALL_SCRIPTS_VERSION = $INSTALL_SCRIPTS_VERSION
GIST_USER = $GIST_USER
LIST_URL = $LIST_URL
INSTALL_SCRIPTS_URL = $INSTALL_SCRIPTS_URL
INSTALL_SCRIPTS_LOC = $INSTALL_SCRIPTS_LOC
EOM
;;
-h | --help | help)
cat << EOM
install_scripts v$INSTALL_SCRIPTS_VERSION
Usage: install_scripts [command]
Without any argument, it offers the scripts you can download.
commands:
-h, --help, help Print this help message
upgrade Upgrade the install_scripts function
reload Reload the install_scripts function
version Print the currently loaded version of install_scripts
settings Print the (hardcoded) script settings
install Show the available scripts and let you install the ones you want
update Update any of the scripts already installed to the latest version
EOM
;;
update)
LIST_DATA=`curl -sSL $LIST_URL`
selections=$(command ls ~/bin | tr '\n' '|')
echo $LIST_DATA | awk -v selects="$selections" -v gistuser="$GIST_USER" -v vbose="$INSTALL_SCRIPTS_DEBUG" -v qstr="$DT" '{ split(selects, sels,"|"); for(s in sels) { if(sels[s] == $2) { print "Downloading",$2,"to ~/bin/"$2,"and marking as executable" ; if(vbose == 1) { print "> curl -SL --progress-bar https://gist.githubusercontent.com/"gistuser"/"$1"/raw/"$2qstr" -o ~/bin/"$2" && chmod +x ~/bin/"$2; } system("curl -SL --progress-bar https://gist.githubusercontent.com/"gistuser"/"$1"/raw/"$2qstr" -o ~/bin/"$2" && chmod +x ~/bin/"$2) } } }'
;;
install | *)
LIST_DATA=`curl -sSL $LIST_URL`
echo 'Here are the available scripts:'
echo $LIST_DATA | awk '{ print NR")",$2; }'
echo -e "Please enter your desired selections, separated by spaces: \c "
read selections
echo $LIST_DATA | awk -v selects="$selections" -v gistuser="$GIST_USER" -v vbose="$INSTALL_SCRIPTS_DEBUG" -v qstr="$DT" '{ split(selects, sels); for(s in sels) { if(sels[s] == NR) { print "Downloading",$2,"to ~/bin/"$2,"and marking as executable" ; if(vbose == 1) { print "> curl -SL --progress-bar https://gist.githubusercontent.com/"gistuser"/"$1"/raw/"$2qstr" -o ~/bin/"$2" && chmod +x ~/bin/"$2; } system("curl -SL --progress-bar https://gist.githubusercontent.com/"gistuser"/"$1"/raw/"$2qstr" -o ~/bin/"$2" && chmod +x ~/bin/"$2) } } }'
;;
esac
}
@henderea
Copy link
Author

henderea commented Jan 9, 2018

Download with:

curl -sSL https://gist.githubusercontent.com/henderea/98aebdafe6ddb030d1de61d47c4b87ef/raw/install_scripts.sh -o ~/.install_scripts.sh

Add this to your ~/.bashrc or ~/.zshrc to enable:

[[ -s "$HOME/.install_scripts.sh" ]] && source "$HOME/.install_scripts.sh" # Load the install_scripts function

To get it in your current session after first download, run:

source ~/.install_scripts.sh

And upgrade with this command:

install_scripts upgrade

Reload the shell function with:

install_scripts reload

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