Prepend /usr and /opt to ensure they come before /bin

Bo Jeanes 2020-10-24 17:47:00 +11:00 committed by GitHub
parent 22ad16a8cb
commit ffe9e6eace
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 5 deletions

View File

@ -1,3 +1,8 @@
## TODO: remove duplicates when appending/prepending
## TODO: Ideally, __prepend will add (or move existing) entry to front while __append will add (or move)
## entry to back. Anything unmentioned should stay in the middle and anything mentioned should not
## be doubled up with system-provided.
function __prepend_path { function __prepend_path {
if [ -z "$(eval echo \$$1)" ]; then if [ -z "$(eval echo \$$1)" ]; then
eval "$1=\"$2\"" eval "$1=\"$2\""
@ -14,15 +19,17 @@ function __append_path {
fi fi
} }
[ -d '/usr/local/bin' ] && __prepend_path "PATH" "/usr/local/bin"
[ -d '/usr/local/sbin' ] && __prepend_path "PATH" "/usr/local/sbin"
[ -d '/opt/local/bin' ] && __prepend_path "PATH" "/opt/local/bin"
[ -d '/opt/local/sbin' ] && __prepend_path "PATH" "/opt/local/sbin"
[ -d '/opt/bin' ] && __prepend_path "PATH" "/opt/bin"
[ -d '/opt/sbin' ] && __prepend_path "PATH" "/opt/sbin"
[ -d "$HOME/bin" ] && __prepend_path "PATH" "$HOME/bin" [ -d "$HOME/bin" ] && __prepend_path "PATH" "$HOME/bin"
[ -d "$HOME/.local/bin" ] && __prepend_path "PATH" "$HOME/.local/bin" [ -d "$HOME/.local/bin" ] && __prepend_path "PATH" "$HOME/.local/bin"
[ -d "$HOME/.cargo/bin" ] && __prepend_path "PATH" "$HOME/.cargo/bin" [ -d "$HOME/.cargo/bin" ] && __prepend_path "PATH" "$HOME/.cargo/bin"
[ -d "$HOME/.emacs.d/bin" ] && __prepend_path "PATH" "$HOME/.emacs.d/bin" [ -d "$HOME/.emacs.d/bin" ] && __prepend_path "PATH" "$HOME/.emacs.d/bin"
[ -d "$HOME/.dotfiles/bin" ] && __prepend_path "PATH" "$HOME/.dotfiles/bin" [ -d "$HOME/.dotfiles/bin" ] && __prepend_path "PATH" "$HOME/.dotfiles/bin"
[ -d '/usr/local/bin' ] && __append_path "PATH" "/usr/local/bin"
[ -d '/usr/local/sbin' ] && __append_path "PATH" "/usr/local/sbin"
[ -d '/opt/local/bin' ] && __append_path "PATH" "/opt/local/bin"
[ -d '/opt/local/sbin' ] && __append_path "PATH" "/opt/local/sbin"
[ -d '/usr/X11/bin' ] && __append_path "PATH" "/usr/X11/bin" [ -d '/usr/X11/bin' ] && __append_path "PATH" "/usr/X11/bin"
[ -d '/usr/bin' ] && __append_path "PATH" "/usr/bin" [ -d '/usr/bin' ] && __append_path "PATH" "/usr/bin"
[ -d '/usr/sbin' ] && __append_path "PATH" "/usr/sbin" [ -d '/usr/sbin' ] && __append_path "PATH" "/usr/sbin"