Skip to content

Instantly share code, notes, and snippets.

@heph
Last active December 15, 2015 14:28
Show Gist options
  • Save heph/5274247 to your computer and use it in GitHub Desktop.
Save heph/5274247 to your computer and use it in GitHub Desktop.
load environment variables from a per-directory rc file, reset to default upon entering any directory which doesn't have a .dirrc owned by your current user
# source each directory's .dirrc for project-specific environment variables
function cd () {
builtin cd "$@"
if [[ $PWD == $HOME* ]]; then
DIRPATH=( $(pwd) )
i=$((${#DIRPATH[@]} - 1))
while [ -O ${DIRPATH[$i]} ]; do
DIRPATH=("${DIRPATH[$i]}/.." "${DIRPATH[@]}")
done
for d in ${DIRPATH[@]}; do
[ -O "$d/.dirrc" ] && source "$d/.dirrc"
done
else
source ~/.bashrc
fi
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment