Skip to content

Instantly share code, notes, and snippets.

@r10r
Created March 25, 2012 20:18
Show Gist options
  • Save r10r/2199513 to your computer and use it in GitHub Desktop.
Save r10r/2199513 to your computer and use it in GitHub Desktop.
Make adding paths to $PATH and exporting environment variables easy
# Add all paths listed in ~/.path to the PATH variable
# ----------------------------------------------------------
# first check if the file is available
if [ -f $HOME/.path ]; then
# read file line-by-line
for p in $(cat $HOME/.path); do
# check if line is a comment
if ! echo $p | grep -q ^[[:space:]]*\#; then
# check if the directory exists
if [ -d "$HOME/$p" ]; then
# finally add it to the PATH environent variable
PATH=$HOME/$p:$PATH
fi
fi
done
fi
# Export all declared environment variables listed in ~/.env
# check with 'env' so see what is exported
# ----------------------------------------------------------
# first check if the file is available
if [ -f $HOME/.env ]; then
# read file line-by-line
for e in $(cat $HOME/.env); do
# check if line is a comment
if ! echo $p | grep -q ^[[:space:]]*\#; then
export $e
fi
done
fi
# Load RVM into a shell session *as a function*
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment