Merge pull request #757 from skwp/path-duplicates

Prevent duplicate entries in $PATH. Fixes #690
This commit is contained in:
Yan Pritzker
2017-07-03 14:45:02 -05:00
committed by GitHub

View File

@@ -1,7 +1,14 @@
# path, the 0 in the filename causes this to load first
path=(
$path
$HOME/.yadr/bin
$HOME/.yadr/bin/yadr
)
pathAppend() {
# Only adds to the path if it's not already there
if ! echo $PATH | egrep -q "(^|:)$1($|:)" ; then
PATH=$PATH:$1
fi
}
# Remove duplicate entries from PATH:
PATH=$(echo "$PATH" | awk -v RS=':' -v ORS=":" '!a[$1]++{if (NR > 1) printf ORS; printf $a[$1]}')
pathAppend "$HOME/.yadr/bin"
pathAppend "$HOME/.yadr/bin/yadr"