Created
November 14, 2012 09:39
-
-
Save akheron/4071242 to your computer and use it in GitHub Desktop.
Change to virtualenv when cd'ing to a directory
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
| # If a directory contains a file named .venv, read its contents and activate | |
| # the corresponding virtualenv. | |
| venv_cd() { | |
| local venv | |
| if builtin cd "$@"; then | |
| if [ -e .venv ]; then | |
| venv=$(cat .venv) | |
| if [ -z "$VIRTUAL_ENV" ]; then | |
| workon "$venv" || true | |
| elif [ "$(basename $VIRTUAL_ENV)" != "$venv" ]; then | |
| workon "$venv" || true | |
| fi | |
| fi | |
| else | |
| return $? | |
| fi | |
| } | |
| alias cd="venv_cd" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment