Last active
December 15, 2015 14:28
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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