Skip to main content

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.
```|

update note: I wrote this for zsh but it works for bash as well.

Here is a trick i use to keep my path clean. (note i load in zsh configs as seperate files. this file needs to load first so an easy way to force that while maintaining standardized naming conventions is to use prefixes. prefixing with 0_pathfix.zsh will cause this to run before the other zsh 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.
```|

update note: I wrote this for zsh but it works for bash as well.

Here is a trick I use to keep my path clean. (Note: I load in zsh configs as separate files. This file needs to load first so an easy way to force that while maintaining standardized naming conventions is to use prefixes. Prefixing with 0_pathfix.zsh will cause this to run before the other Zsh 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.
added 74 characters in body
Source Link

update note: I wrote this for zsh but it works for bash as well.

Here is a trick i use to keep my path clean. (note i load in zsh configs as seperate files. this file needs to load first so an easy way to force that while maintaining standardized naming conventions is to use prefixes. prefixing with 0_pathfix.zsh will cause this to run before the other zsh 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.
```|

Here is a trick i use to keep my path clean. (note i load in zsh configs as seperate files. this file needs to load first so an easy way to force that while maintaining standardized naming conventions is to use prefixes. prefixing with 0_pathfix.zsh will cause this to run before the other zsh 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.

update note: I wrote this for zsh but it works for bash as well.

Here is a trick i use to keep my path clean. (note i load in zsh configs as seperate files. this file needs to load first so an easy way to force that while maintaining standardized naming conventions is to use prefixes. prefixing with 0_pathfix.zsh will cause this to run before the other zsh 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.
```|
Source Link

Here is a trick i use to keep my path clean. (note i load in zsh configs as seperate files. this file needs to load first so an easy way to force that while maintaining standardized naming conventions is to use prefixes. prefixing with 0_pathfix.zsh will cause this to run before the other zsh 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.