update note: I wrote this for zsh but it works for bash as well.
Here is a trick iI use to keep my path clean.
(note iNote: I load in zsh configs as seperateseparate files. thisThis file needs to load first so an easy way to force that while maintaining standardized naming conventions is to use prefixes. prefixingPrefixing with 0_pathfix.zsh0_pathfix.zsh
will cause this to run before the other zshZsh config files.)
# add to path if $1 is not already in path
pathAppend() {
if ! echo $PATH | egrep -q "(^|:)$1($|:)" ; then
PATH=$PATH:$1
fi
}
# filters the path checking against itself for duplicates returns clean path then exports the clean path.
PATH=$(echo "$PATH" | awk -v RS=':' -v ORS=":" '!a[$1]++{if (NR > 1) printf ORS; printf $a[$1]}'); export PATH;
# This ensures that even if you manually added to the path the next time zsh source is reloaded the path will clean itself.
```|