Add support .venv folder as virtual env

This commit is contained in:
Lei Zhang 2013-10-16 15:44:49 +08:00 committed by Benjamin Bach
commit dd3f92fe97

View file

@ -1,10 +1,5 @@
virtualenvwrapper='virtualenvwrapper_lazy.sh' virtualenvwrapper='virtualenvwrapper_lazy.sh'
if (( $+commands[$virtualenvwrapper] )); then if (( $+commands[$virtualenvwrapper] )); then
if [[ "$WORKON_HOME" == "" ]]; then
echo "\$WORKON_HOME is not defined so ZSH plugin virtualenvwrapper will not work"
else
source ${${virtualenvwrapper}:c} source ${${virtualenvwrapper}:c}
if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then
@ -22,6 +17,8 @@ if (( $+commands[$virtualenvwrapper] )); then
# Check for virtualenv name override # Check for virtualenv name override
if [[ -f "$PROJECT_ROOT/.venv" ]]; then if [[ -f "$PROJECT_ROOT/.venv" ]]; then
ENV_NAME=`cat "$PROJECT_ROOT/.venv"` ENV_NAME=`cat "$PROJECT_ROOT/.venv"`
elif [[ -f "$PROJECT_ROOT/.venv/bin/activate" ]];then
ENV_NAME="$PROJECT_ROOT/.venv"
elif [[ "$PROJECT_ROOT" != "." ]]; then elif [[ "$PROJECT_ROOT" != "." ]]; then
ENV_NAME=`basename "$PROJECT_ROOT"` ENV_NAME=`basename "$PROJECT_ROOT"`
else else
@ -32,6 +29,8 @@ if (( $+commands[$virtualenvwrapper] )); then
if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then
if [[ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]]; then if [[ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]]; then
workon "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME" workon "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME"
elif [[ -e "$ENV_NAME/bin/activate" ]]; then
source $ENV_NAME/bin/activate && export CD_VIRTUAL_ENV="$ENV_NAME"
fi fi
fi fi
elif [ $CD_VIRTUAL_ENV ]; then elif [ $CD_VIRTUAL_ENV ]; then
@ -55,7 +54,6 @@ if (( $+commands[$virtualenvwrapper] )); then
set -A chpwd_functions workon_cwd set -A chpwd_functions workon_cwd
fi fi
fi fi
fi
else else
print "zsh virtualenvwrapper plugin: Cannot find ${virtualenvwrapper}. Please install with \`pip install virtualenvwrapper\`." print "zsh virtualenvwrapper plugin: Cannot find ${virtualenvwrapper}. Please install with \`pip install virtualenvwrapper\`."
fi fi