Created
April 21, 2013 11:45
-
-
Save revolunet/5429335 to your computer and use it in GitHub Desktop.
automatic virtualenv discovery & activation on path change.
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
| # | |
| # adapted from http://www.burgundywall.com/tech/automatically-activate-virtualenv | |
| # source this in your .bash_profile and you're done | |
| # | |
| # todo: ability to set a different virtualenv name | |
| # | |
| export PREVPWD=`pwd` | |
| export PREVENV_PATH= | |
| handle_virtualenv(){ | |
| if [ "$PWD" != "$PREVPWD" ]; then | |
| PREVPWD="$PWD"; | |
| if [ -n "$PREVENV_PATH" ]; then | |
| if [ "`echo "$PWD" | grep -c $PREVENV_PATH`" = "0" ]; then | |
| deactivate | |
| unalias python 2> /dev/null | |
| PREVENV_PATH= | |
| fi | |
| fi | |
| # activate virtualenv dynamically | |
| if [ -e "$PWD/.venv" ] && [ "$PWD" != "$PREVENV_PATH" ]; then | |
| PREVENV_PATH="$PWD" | |
| workon `basename $PWD` | |
| fi | |
| fi | |
| } | |
| export PROMPT_COMMAND=handle_virtualenv | |
| export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages' | |
| export WORKON_HOME=~/.virtualenvs | |
| source /usr/local/bin/virtualenvwrapper.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment