833e6f5958b9851d2dbcf8ae706474af4079a25e

Author
Jyrki Pulliainen <jyrki@spotify.com>
Committer
Jyrki Pulliainen <jyrki@spotify.com>
Date

Message

virtualenvwrapper: Deactivate only if in virtualenv

If user manually deactivates the virtualenv when using this mode, zsh
will produce following error:

    deactivate:12: command not found: virtualenv_deactivate

To avoid this, check that the VIRTUAL_ENV flag is set before trying to
automatically deactivate the virtual environment.

Fixes #2185

Diff

 1diff --git a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
 2index 52e02d3e01390c77f669d2fa657d2b65e7ae5029..217ab0722dd3cb022ba9fa8bf8226629c58ab713 100644
 3--- a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
 4+++ b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
 5@@ -38,7 +38,7 @@ if (( $+commands[$virtualenvwrapper] )); then
 6                 source $ENV_NAME/bin/activate && export CD_VIRTUAL_ENV="$ENV_NAME"
 7               fi
 8             fi
 9-          elif [ $CD_VIRTUAL_ENV ]; then
10+          elif [[ -n $CD_VIRTUAL_ENV && -n $VIRTUAL_ENV ]]; then
11             # We've just left the repo, deactivate the environment
12             # Note: this only happens if the virtualenv was activated automatically
13             deactivate && unset CD_VIRTUAL_ENV