From a8240323385b3114143ae510bbef34c48ba6e264 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 9 Jul 2026 06:42:28 +0000 Subject: [PATCH 1/2] Add sh-compatible path_prefix and path_postfix helpers for dynamic PATH Introduce path_prefix and path_postfix in .profile to prepend and append PATH entries while skipping duplicates. Refactor static PATH assignments to use these helpers, source .profile from .bash_profile for login shells, and replace the hardcoded opencode PATH in .bashrc with path_prefix. Co-authored-by: Anurup Dey --- bash/.bash_profile | 1 + bash/.bashrc | 9 ++++++++- bash/.profile | 34 ++++++++++++++++++++++++++++------ 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/bash/.bash_profile b/bash/.bash_profile index 5545f00..ad8dc45 100644 --- a/bash/.bash_profile +++ b/bash/.bash_profile @@ -2,4 +2,5 @@ # ~/.bash_profile # +[[ -f ~/.profile ]] && . ~/.profile [[ -f ~/.bashrc ]] && . ~/.bashrc diff --git a/bash/.bashrc b/bash/.bashrc index 52f8e93..f42f8a4 100644 --- a/bash/.bashrc +++ b/bash/.bashrc @@ -183,4 +183,11 @@ type -P cdl.sh &>/dev/null && source cdl.sh # this is also like an alias #----------------------------------------------------------------------- # opencode -export PATH=/home/deyloop/.opencode/bin:$PATH +if type path_prefix >/dev/null 2>&1; then + path_prefix "$HOME/.opencode/bin" +else + case ":${PATH}:" in + *:"$HOME/.opencode/bin":*) ;; + *) export PATH="$HOME/.opencode/bin:$PATH" ;; + esac +fi diff --git a/bash/.profile b/bash/.profile index f7a4f54..2eeb3da 100644 --- a/bash/.profile +++ b/bash/.profile @@ -55,14 +55,36 @@ export REPOS_DIR="$HOME/repos" #----------------------------------PATH--------------------------------- -PATH="$CARGO_HOME:$PATH" -PATH="$SCRIPTS_DIR:$PATH" -PATH="$HOME/.local/bin:$PATH" -PATH="$PATH:$HOME/.local/go/bin" +# Prepend directories to PATH, skipping any that are already present. +path_prefix() { + _path_prefix_dir= + for _path_prefix_dir in "$@"; do + case ":${PATH}:" in + *:"${_path_prefix_dir}":*) ;; + *) PATH="${_path_prefix_dir}:${PATH}" ;; + esac + done + export PATH + unset _path_prefix_dir +} + +# Append directories to PATH, skipping any that are already present. +path_postfix() { + _path_postfix_dir= + for _path_postfix_dir in "$@"; do + case ":${PATH}:" in + *:"${_path_postfix_dir}":*) ;; + *) PATH="${PATH}:${_path_postfix_dir}" ;; + esac + done + export PATH + unset _path_postfix_dir +} + +path_prefix "$CARGO_HOME" "$SCRIPTS_DIR" "$HOME/.local/bin" export GOPATH="$HOME/.local/go/packages" -PATH="$PATH:$GOPATH/bin" -export PATH +path_postfix "$HOME/.local/go/bin" "$GOPATH/bin" #----------------------------------------------------------------------- From 3aec60a0fa7b2da68ebd01ba5539c6a6ec87753f Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 9 Jul 2026 06:44:21 +0000 Subject: [PATCH 2/2] Skip PATH entries when install directory is missing path_prefix and path_postfix now require each directory to exist before adding it to PATH. The opencode fallback in .bashrc uses the same check. Co-authored-by: Anurup Dey --- bash/.bashrc | 4 +++- bash/.profile | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/bash/.bashrc b/bash/.bashrc index f42f8a4..1f8c924 100644 --- a/bash/.bashrc +++ b/bash/.bashrc @@ -188,6 +188,8 @@ if type path_prefix >/dev/null 2>&1; then else case ":${PATH}:" in *:"$HOME/.opencode/bin":*) ;; - *) export PATH="$HOME/.opencode/bin:$PATH" ;; + *) + [ -d "$HOME/.opencode/bin" ] && export PATH="$HOME/.opencode/bin:$PATH" + ;; esac fi diff --git a/bash/.profile b/bash/.profile index 2eeb3da..609071e 100644 --- a/bash/.profile +++ b/bash/.profile @@ -55,10 +55,11 @@ export REPOS_DIR="$HOME/repos" #----------------------------------PATH--------------------------------- -# Prepend directories to PATH, skipping any that are already present. +# Prepend directories to PATH, skipping any that are already present or missing. path_prefix() { _path_prefix_dir= for _path_prefix_dir in "$@"; do + [ -d "$_path_prefix_dir" ] || continue case ":${PATH}:" in *:"${_path_prefix_dir}":*) ;; *) PATH="${_path_prefix_dir}:${PATH}" ;; @@ -68,10 +69,11 @@ path_prefix() { unset _path_prefix_dir } -# Append directories to PATH, skipping any that are already present. +# Append directories to PATH, skipping any that are already present or missing. path_postfix() { _path_postfix_dir= for _path_postfix_dir in "$@"; do + [ -d "$_path_postfix_dir" ] || continue case ":${PATH}:" in *:"${_path_postfix_dir}":*) ;; *) PATH="${PATH}:${_path_postfix_dir}" ;;