Last active
August 29, 2015 14:01
-
-
Save codemonkey2841/dd95cd8f9c87759f276f to your computer and use it in GitHub Desktop.
Auto workon/deactivate a python virtualenv
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
function has_virtualenv() { | |
if [[ $PWD == $PROJECT_HOME* ]]; then | |
PRJCT_NAME=$(echo ${PWD//$PROJECT_HOME/} | cut -f 2 -d /) | |
if [ -n "$PRJCT_NAME" ]; then | |
if [ -e $WORKON_HOME/$PRJCT_NAME ]; then | |
if [ -z "$VIRTUAL_ENV" ]; then | |
workon $PRJCT_NAME | |
fi | |
return | |
fi | |
fi | |
fi | |
if [ -n "$VIRTUAL_ENV" ]; then | |
deactivate &> /dev/null | |
fi | |
} | |
function venv_cd() { | |
cd "$@" && has_virtualenv | |
} | |
alias cd="venv_cd" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment