From 5e4648a49e8c18b86f31e8b2227e5f4e6511cc17 Mon Sep 17 00:00:00 2001 From: nirenjan Date: Wed, 30 Jan 2013 10:27:39 -0800 Subject: [PATCH] Tweak bashrc.common Add a function add_to_path so that it can prepend any specified path to the PATH environment variable, but only if it is not already there. Don't worry about (re)setting the LS_COLORS environment if it's already been set by the system bashrc. --- bash/bashrc.common | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/bash/bashrc.common b/bash/bashrc.common index 7078f87..97ebd0e 100644 --- a/bash/bashrc.common +++ b/bash/bashrc.common @@ -1,3 +1,10 @@ +# Add path function: check if path exists in $PATH, only then prepend the +# specified path to PATH +add_to_path() { + if [[ ! -z $1 && -d $1 && ":$PATH:" != *":$1:"* ]]; then + export PATH=$1:$PATH + fi +} # Import the Git prompt shell functions. These can be found # @github:git/git/contrib/completion/git_prompt.sh @@ -9,13 +16,11 @@ else fi # Add $HOME/bin to PATH -if [[ ":$PATH:" != *":$HOME/bin:"* ]] -then - export PATH=$HOME/bin:$PATH -fi +add_to_path $HOME/bin # Add ls coloring -if [ -f $HOME/.bashrc.lscolors ]; then +# Don't bother if LS_COLORS is already set +if [[ -z $LS_COLORS && -f $HOME/.bashrc.lscolors ]]; then source $HOME/.bashrc.lscolors fi