dotfiles

Personal dotfiles
git clone https://git.bracken.jp/dotfiles.git
Log | Files | Refs | LICENSE

paths (1125B)


      1 # .paths
      2 
      3 # Cleanly remove $1 from $PATH
      4 path_remove() {
      5   if [ -n "$ZSH_VERSION" ]; then
      6     local paths=("${(s/:/)PATH}")
      7     paths=("${(@)paths:#$1}")
      8     export PATH="${(j/:/)paths}"
      9   else
     10     PATH=$(echo $PATH | sed "s:^$1\:::;s:\:$1\::\::;s:\:$1::")
     11   fi
     12 }
     13 
     14 # Move/add $1 to the start of $PATH
     15 path_prepend() {
     16   path_remove "$1"
     17   if [ -d "$1" ]; then
     18     export PATH="$1:$PATH"
     19   fi
     20 }
     21 
     22 # Move/add $1 to the end of $PATH
     23 path_append() {
     24   path_remove "$1"
     25   if [ -d "$1" ]; then
     26     export PATH="$PATH:$1"
     27   fi
     28 }
     29 
     30 # Push /usr/local/bin to the front of PATH
     31 path_prepend "/usr/local/bin"
     32 
     33 # Google Cloud SDK
     34 path_prepend "$SRC_ROOT/google-cloud-sdk/bin"
     35 
     36 # Homebrew
     37 if [[ "$(uname)" == "Darwin" ]]; then
     38   path_prepend "$HOME/.homebrew/bin"
     39 fi
     40 
     41 # Ruby gems
     42 if which ruby >/dev/null && which gem >/dev/null; then
     43   path_prepend "$(ruby -r rubygems -e 'puts Gem.user_dir')/bin"
     44 fi
     45 
     46 # Python modules
     47 if which python3 >/dev/null; then
     48   path_prepend "$(python3 -m site --user-base)/bin"
     49 fi
     50 
     51 # Rust packages
     52 path_prepend "$HOME/.cargo/bin"
     53 
     54 # Personal bin directory
     55 path_prepend "$HOME/.local/bin"
     56 path_prepend "$HOME/bin"