Dynamically build path without duplicates and only for existing directories

pull/2/head
Bodaniel Jeanes 2012-01-04 21:41:41 -06:00
parent 9827b76c4c
commit d91dca4990
2 changed files with 21 additions and 3 deletions

View File

@ -1,8 +1,6 @@
COMMON_SHELL_FILES="$SHELL_FILES/../common" COMMON_SHELL_FILES="$SHELL_FILES/../common"
# TODO: Remove duplicates from the PATH source "$SHELL_FILES/../path.sh"
PATH="/usr/local/bin:/usr/local/sbin:/usr/X11/bin:/usr/bin:/usr/sbin:/bin:/sbin:${PATH}"
source "$SHELL_FILES/../tmux.sh" source "$SHELL_FILES/../tmux.sh"
CDPATH=".:${HOME}" CDPATH=".:${HOME}"

20
shells/path.sh 100644
View File

@ -0,0 +1,20 @@
function __append_path {
if [ -z "$(eval echo \$$1)" ]; then
eval "$1=\"$2\""
else
eval "$1=\"\$$1:$2\""
fi
}
[ -d "$HOME/bin" ] && __append_path "new_path" "$HOME/bin"
[ -d "$DOT_FILES/bin" ] && __append_path "new_path" "$DOT_FILES/bin"
[ -d '/usr/local/bin' ] && __append_path "new_path" "/usr/local/bin"
[ -d '/usr/local/sbin' ] && __append_path "new_path" "/usr/local/sbin"
[ -d '/opt/local/bin' ] && __append_path "new_path" "/opt/local/bin"
[ -d '/opt/local/sbin' ] && __append_path "new_path" "/opt/local/sbin"
[ -d '/usr/X11/bin' ] && __append_path "new_path" "/usr/X11/bin"
[ -d '/usr/bin' ] && __append_path "new_path" "/usr/bin"
[ -d '/usr/sbin' ] && __append_path "new_path" "/usr/sbin"
[ -d '/bin' ] && __append_path "new_path" "/bin"
[ -d '/sbin' ] && __append_path "new_path" "/sbin"
PATH="$new_path"