Created
July 25, 2018 23:45
-
-
Save dingus9/9e81da31ca59e37e298bafe90dc4aa4c to your computer and use it in GitHub Desktop.
Bash util functions
This file contains 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
pathadd() { | |
# Add a bin to path if it isn't there already | |
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; | |
then | |
if [ "$2" == "pre" ]; | |
then | |
PATH="$1:$PATH"; | |
else | |
PATH="${PATH:+"$PATH:"}$1"; | |
fi | |
fi | |
} | |
pathdel() { | |
local tmp_bin_path | |
# End condition | |
if [[ ":$PATH:" == *":$1:" ]]; then | |
tmp_bin_path="${1//\//\\/}" | |
PATH="${PATH//:$tmp_bin_path/}" | |
elif [[ ":$PATH:" == *":$1:"* ]]; then | |
tmp_bin_path="${1//\//\\/}" | |
PATH="${PATH//$tmp_bin_path:/}" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment