From 1684a2319a9d4312e711c044263dee15f9860254 Mon Sep 17 00:00:00 2001 From: Pavel Puchkin Date: Fri, 22 Jun 2012 23:32:29 +1100 Subject: [PATCH] Bugfix - plugin wont deactivate venv in some cases ...when changing directory directly from git repo to another repo, which have not associated virtualenv --- .../virtualenvwrapper/virtualenvwrapper.plugin.zsh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh index e7100db9a..1b214fb5f 100644 --- a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh +++ b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh @@ -20,17 +20,25 @@ for wrapsource in "/usr/local/bin/virtualenvwrapper.sh" "/etc/bash_completion.d/ if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then if [[ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]]; then workon "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME" + else + _deactivate fi fi - elif [ $CD_VIRTUAL_ENV ]; then + else # We've just left the repo, deactivate the environment # Note: this only happens if the virtualenv was activated automatically - deactivate && unset CD_VIRTUAL_ENV + _deactivate fi unset REPO_ROOT unset ENV_NAME } + function _deactivate() { + if [[ -n $CD_VIRTUAL_ENV ]]; then + deactivate && unset CD_VIRTUAL_ENV + fi + } + # New cd function that does the virtualenv magic function cd { builtin cd "$@" && _workon_cwd