Created
September 23, 2013 23:29
-
-
Save kn/6678405 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
### | |
# Automatically activate virtualenv if appropriate. | |
# This assumes virtualenvs are either: | |
# - in $WORKON_HOME folder, in which case it uses workon command to activate the virtualenv. | |
# - in ./local folder, in which case it uses ./setenv.sh to activate the virtualenv. | |
# Note: This will have a conflict if other script overrides cd command. | |
# e.g. rvm overrides cd command for local .rvm file. | |
### | |
cd() { | |
if builtin cd "$@"; then | |
if [[ -s ./setenv.sh ]]; then | |
if [[ "$(basename ./${VIRTUAL_ENV})" != "local" ]]; then | |
if [[ "$@" != "." ]]; then | |
source ./setenv.sh ""; | |
fi | |
fi | |
elif [[ -s ${WORKON_HOME}/$(basename ${PWD}) ]]; then | |
if [[ "$(basename ./${VIRTUAL_ENV})" != "$(basename ${PWD})" ]]; then | |
workon $(basename ${PWD}); | |
fi | |
fi | |
else | |
return $?; | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment