diff --git a/shells/bootstrap.sh b/shells/bootstrap.sh index 78ea2b8..f880a77 100644 --- a/shells/bootstrap.sh +++ b/shells/bootstrap.sh @@ -1,8 +1,6 @@ COMMON_SHELL_FILES="$SHELL_FILES/../common" -# TODO: Remove duplicates from the PATH -PATH="/usr/local/bin:/usr/local/sbin:/usr/X11/bin:/usr/bin:/usr/sbin:/bin:/sbin:${PATH}" - +source "$SHELL_FILES/../path.sh" source "$SHELL_FILES/../tmux.sh" CDPATH=".:${HOME}" diff --git a/shells/path.sh b/shells/path.sh new file mode 100644 index 0000000..c0a125e --- /dev/null +++ b/shells/path.sh @@ -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"