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..1f8c924 100644 --- a/bash/.bashrc +++ b/bash/.bashrc @@ -183,4 +183,13 @@ 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":*) ;; + *) + [ -d "$HOME/.opencode/bin" ] && export PATH="$HOME/.opencode/bin:$PATH" + ;; + esac +fi diff --git a/bash/.profile b/bash/.profile index f7a4f54..609071e 100644 --- a/bash/.profile +++ b/bash/.profile @@ -55,14 +55,38 @@ 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 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}" ;; + esac + done + export PATH + unset _path_prefix_dir +} + +# 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}" ;; + 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" #-----------------------------------------------------------------------