Last active
April 11, 2017 01:09
-
-
Save xiaohk/f1dfbbd156aec873cc315d5a27443503 to your computer and use it in GitHub Desktop.
Automatically activate virtualenv when cd into project directory
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
# Automatically activate virtualenv when using 'cd' (rewrite builtin cd function) | |
# Assuming current working directory is in a sub-directory of virtualenv directory | |
function cd { | |
builtin cd "$@" | |
# Check upper 4 directories | |
if [-d "../bin" -a -d "../lib" -a -d "../include" -a -e "../.Python" \ | |
-a -e "../pip-selfcheck.json" ] ; then | |
source ../bin/activate | |
elif [ -d "../../bin" -a -d "../../lib" -a -d "../../include" -a -e \ | |
"../../.Python" -a -e "../../pip-selfcheck.json" ] ; then | |
source ../../bin/activate | |
elif [ -d "../../../bin" -a -d "../../../lib" -a -d "../../../include" \ | |
-a -e "../../../.Python" -a -e "../../../pip-selfcheck.json" ] ; then | |
source ../../../bin/activate | |
elif [ -d "../../../../bin" -a -d "../../../../lib" -a -d \ | |
"../../../../include" -a -e "../../../../.Python" -a -e \ | |
"../../../../pip-selfcheck.json" ] ; then | |
source ../../../../bin/activate | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment