Skip to content

Instantly share code, notes, and snippets.

@webee
Created April 6, 2017 15:59
Show Gist options
  • Save webee/76dd1c893181e822a182bda8a41440d8 to your computer and use it in GitHub Desktop.
Save webee/76dd1c893181e822a182bda8a41440d8 to your computer and use it in GitHub Desktop.
pathmunge
function pathmunge {
if echo $PATH | /usr/bin/egrep -q "(^|:)$1($|:)";then
a=${1//\//\\\/}
PATH=$(echo $PATH|/usr/bin/sed -e "s/\([:^]*\)$a\([$:]*\)/\1\2/g")
PATH=$(echo $PATH|/usr/bin/sed -e 's/::/:/g'|/usr/bin/sed -e 's/^://g'|/usr/bin/sed -e 's/:$//g')
fi
if [ "$2" = "after" ];then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
export PATH
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment