From 4e9c8e8470b5ed3f18e729b3c0234f12833d6d7b Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Mon, 11 Nov 2019 13:04:25 +0100 Subject: [PATCH] Ensure PATH directories are in correct order Previously we only checked if the new directory was already in the PATH and, if yes, didn't prepend it. This can cause the new directory to be in an unexpected position. Now we first remove any occurrences of the new directory (to prevent duplication) and prepend it so it's in the position we expect. --- dotfiles/.config/bash/profile | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/dotfiles/.config/bash/profile b/dotfiles/.config/bash/profile index 923a4dd..e0842f5 100644 --- a/dotfiles/.config/bash/profile +++ b/dotfiles/.config/bash/profile @@ -20,42 +20,50 @@ export LESSHISTFILE="$XDG_CACHE_HOME/less/history" export LESSHISTSIZE=1000 export LOCAL_PREFIX="/usr/local" [ command -v brew &>/dev/null ] && LOCAL_PREFIX=$(brew --prefix) +export MANPATH="$(MANPATH='' manpath)" export PAGER=less export PYTHONSTARTUP="$XDG_CONFIG_HOME/python/startup.py" export VIMINIT='let $MYVIMRC="$XDG_CONFIG_HOME/vim/vimrc" | source $MYVIMRC' +############################################################################## +# Customize PATH (and MANPATH) +############################################################################## + # Prevent path_helper from messing with the PATH when starting tmux. # See: https://superuser.com/a/583502 [ "$(uname)" == "Darwin" ] && { PATH=""; source /etc/profile; } +prepend_dir() { # 1: dir to add, 2: variable to manipulate + [ -d "$1" -a -n "$2" ] || return + local list="${!2}" # capture current value + list=${list#"$1sep"} # remove dir from beginning + list=${list//":$1:"/:} # remove dir from middle + list=${list%":$1"} # remove dir from end + printf -v "$2" "$1${list:+":$list"}" # add in front (use : only if empty) +} + # Add custom bin dirs to PATH if they exist and are not already in PATH. -while read -r dir; do - [ -d "$dir" ] && [[ ":$PATH:" != *":$dir:"* ]] && PATH="$dir:$PATH" -done <