From 04fec2f8154f9fa85cf42435ea952166582a78b4 Mon Sep 17 00:00:00 2001 From: Jason Tavares Date: Thu, 26 Jan 2017 18:08:12 -0500 Subject: [PATCH] Change order of automatic virtualenv activation/deactivation When navigating from a virtualenv project directory, first deactivate the virtualenv. Then, check to see if destination directory is also a virtualenv project directory. If it is activate that virtualenv. See #5817. --- plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh index 6cd30732e..1c529044b 100644 --- a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh +++ b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh @@ -61,6 +61,12 @@ if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then else ENV_NAME="" fi + + if [[ -n $CD_VIRTUAL_ENV && "$ENV_NAME" != "$CD_VIRTUAL_ENV" ]]; then + # We've just left the repo, deactivate the environment + # Note: this only happens if the virtualenv was activated automatically + deactivate && unset CD_VIRTUAL_ENV + fi if [[ "$ENV_NAME" != "" ]]; then # Activate the environment only if it is not already active if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then @@ -70,10 +76,6 @@ if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then source $ENV_NAME/bin/activate && export CD_VIRTUAL_ENV="$ENV_NAME" fi fi - elif [[ -n $CD_VIRTUAL_ENV && -n $VIRTUAL_ENV ]]; then - # We've just left the repo, deactivate the environment - # Note: this only happens if the virtualenv was activated automatically - deactivate && unset CD_VIRTUAL_ENV fi fi }