Skip to content

Instantly share code, notes, and snippets.

@dingus9
Created July 25, 2018 23:45
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 dingus9/9e81da31ca59e37e298bafe90dc4aa4c to your computer and use it in GitHub Desktop.
Save dingus9/9e81da31ca59e37e298bafe90dc4aa4c to your computer and use it in GitHub Desktop.
Bash util functions
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