From 436447160cbd4913eb7c776e81fbca95108584ed Mon Sep 17 00:00:00 2001 From: Brandon Sandrowicz Date: Tue, 20 May 2014 09:41:36 -0400 Subject: [PATCH] Fixing virtualenvwrapper plugin for Ubuntu (and Debian) Ubuntu and Debian store the system-installed virtualenvwrapper in /etc/bash_completion.d/virtualenvwrapper, so that it gets automatically sourced at startup in Bash. By not putting it somewhere in $PATH, they end up excluding others (e.g. Zsh) that might want to use that file. Oops! The virtualenvwrapper plugin should account for this so that Ubuntu (or Debian) users don't end up with this message: zsh virtualenvwrapper plugin: Cannot find virtualenvwrapper.sh. Please install with `pip install virtualenvwrapper`. even when they have a virtualenvwrapper installed to a known location. --- .../virtualenvwrapper.plugin.zsh | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh index f58bda1ad..51577f174 100644 --- a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh +++ b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh @@ -1,8 +1,17 @@ virtualenvwrapper='virtualenvwrapper.sh' -if (( $+commands[$virtualenvwrapper] )); then - source ${${virtualenvwrapper}:c} - if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then +if (( $+commands[$virtualenvwrapper] )); then + source ${${virtualenvwrapper}:c} +elif [[ -f "/etc/bash_completion.d/virtualenvwrapper" ]]; then + virtualenvwrapper="/etc/bash_completion.d/virtualenvwrapper" + source "/etc/bash_completion.d/virtualenvwrapper" +else + print "zsh virtualenvwrapper plugin: Cannot find ${virtualenvwrapper}. Please install with \`pip install virtualenvwrapper\`." + return +fi + +if type workon 2>&1 >/dev/null; then + if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then # Automatically activate Git projects's virtual environments based on the # directory name of the project. Virtual environment name can be overridden # by placing a .venv file in the project root with a virtualenv name in it @@ -53,7 +62,7 @@ if (( $+commands[$virtualenvwrapper] )); then else set -A chpwd_functions workon_cwd fi - fi + fi else - print "zsh virtualenvwrapper plugin: Cannot find ${virtualenvwrapper}. Please install with \`pip install virtualenvwrapper\`." + print "zsh virtualenvwrapper plugin: shell function 'workon' not defined. Please check ${virtualenvwrapper}." >&2 fi