4 ms·
Annoyingly not built in, pathadd and pathrm to make sure re-sourcing your bashrc doesn't hose your environment. pathadd() { newelement=${1%/}
by stevebmark 8y ago
Annoyingly not built in, pathadd and pathrm to make sure re-sourcing your bashrc doesn't hose your environment.
pathadd() {
newelement=${1%/}
if [ -d "$1" ] && ! echo "$PATH" | grep -E -q "(^|:)$newelement($|:)" ; then
if [ "$2" = "after" ] ; then
PATH="$PATH:$newelement"
else
PATH="$newelement:$PATH"
fi
fi
}
pathrm() {
PATH="$(echo $PATH | sed -e "s;\(^\|:\)${1%/}\(:\|\$\);\1\2;g" -e 's;^:\|:$;;g' -e 's;::;:;g')"
}