From bbcf389acee3dd5f23ae7a90395b056509a16ae3 Mon Sep 17 00:00:00 2001 From: Xavier Logerais Date: Sat, 22 Aug 2026 02:10:04 +0200 Subject: [PATCH] feat: Split _path_add into _path_append and _path_prepend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _path_add only ever appended to PATH, which didn't fit profile.d/krew and profile.d/anyenv (they prepend, to take priority). Rename it to _path_append for clarity and add _path_prepend alongside it, so both orderings get the same dedup guard when needed — krew and anyenv aren't converted yet, kept as plain PATH concatenation until then. --- _helpers.bash | 8 +++++++- profile.d/path | 8 ++++---- rc.d/rvm | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/_helpers.bash b/_helpers.bash index 2e32a80..aa3970c 100644 --- a/_helpers.bash +++ b/_helpers.bash @@ -25,12 +25,18 @@ function _source_dir_files() { } # Source : https://superuser.com/questions/39751/add-directory-to-path-if-its-not-already-there -_path_add() { +_path_append() { if [ -d "$1" ] && [[ ":${PATH}:" != *":$1:"* ]]; then PATH="${PATH:+"${PATH}:"}$1" fi } +_path_prepend() { + if [ -d "$1" ] && [[ ":${PATH}:" != *":$1:"* ]]; then + PATH="$1${PATH:+":${PATH}"}" + fi +} + _prompt_command_add() { if [ -n "$1" ] && [[ ":${PROMPT_COMMAND}:" != *":$1:"* ]]; then PROMPT_COMMAND="${PROMPT_COMMAND:+"${PROMPT_COMMAND};"}$1" diff --git a/profile.d/path b/profile.d/path index f4465e4..b5e1bba 100644 --- a/profile.d/path +++ b/profile.d/path @@ -1,6 +1,6 @@ # Customize PATH -_path_add "${HOME}/.bin" -_path_add "${HOME}/.local/bin" +_path_append "${HOME}/.bin" +_path_append "${HOME}/.local/bin" -_path_add "${HOME}/bin" -_path_add "${HOME}/scripts" +_path_append "${HOME}/bin" +_path_append "${HOME}/scripts" diff --git a/rc.d/rvm b/rc.d/rvm index b270f08..b0ed113 100644 --- a/rc.d/rvm +++ b/rc.d/rvm @@ -5,4 +5,4 @@ [[ -r "${HOME}/.rvm/scripts/completion" ]] && source "${HOME}/.rvm/scripts/completion" # Add RVM to PATH for scripting -[[ -r "${HOME}/.rvm/bin" ]] && _path_add "${HOME}/.rvm/bin" +[[ -r "${HOME}/.rvm/bin" ]] && _path_append "${HOME}/.rvm/bin"