From 2570e6272c9ce2bc0826f4362588cdf39af17a8d Mon Sep 17 00:00:00 2001 From: Nick Plekhanov Date: Sun, 4 Sep 2016 03:25:31 +0200 Subject: [PATCH] zshrc: More flexible way to configure PATH variable Add `bin` folder to execute scripts globally --- shell/zshrc | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/shell/zshrc b/shell/zshrc index 6cde88a..315778d 100755 --- a/shell/zshrc +++ b/shell/zshrc @@ -1,9 +1,37 @@ # Path to your oh-my-zsh configuration. export ZSH=$HOME/.oh-my-zsh -# Explicitly configured $PATH variable -export PATH="/usr/local/git/bin:/sw/bin/:/usr/local/bin:/usr/local/:/usr/local/sbin:/usr/local/mysql/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin/" -# export MANPATH="/usr/local/man:$MANPATH" +# Directories to be prepended to $PATH +declare -a dirs_to_prepend +dirs_to_prepend=( + "/usr/bin" + "/usr/local/sbin" + "/usr/local/git/bin" + "/usr/local/" + "/usr/local/mysql/bin" + "/sw/bin/" + "$HOME/dotfiles/bin" + "$HOME/bin" + "$HOME/.rvm/bin" + "$(brew --prefix ruby)/bin" + "$(brew --prefix coreutils)/libexec/gnubin" # Add brew-installed GNU core utilities bin + "$(brew --prefix)/share/npm/bin" # Add npm-installed package bin +) + +# Explicitly configured $PATH +PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" + +for dir in ${(k)dirs_to_prepend[@]} +do + if [ -d ${dir} ]; then + # If these directories exist, then prepend them to existing PATH + PATH="${dir}:$PATH" + fi +done + +unset dirs_to_prepend + +export PATH # Set name of the theme to load. # Look in ~/.oh-my-zsh/themes/