4161aa4f9de45233bdee7073933498422a50d213

Author
Brandon Sandrowicz <brandon@sandrowicz.org>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

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.

Diff

 1diff --git a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
 2index 217ab0722dd3cb022ba9fa8bf8226629c58ab713..9a0616b72dfa1cdf7497e26f1747f5459e9f9498 100644
 3--- a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
 4+++ b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
 5@@ -1,12 +1,19 @@
 6 virtualenvwrapper='virtualenvwrapper.sh'
 7-if (( $+commands[$virtualenvwrapper] )); then
 8 
 9+if (( $+commands[$virtualenvwrapper] )); then
10   source ${${virtualenvwrapper}:c}
11+elif [[ -f "/etc/bash_completion.d/virtualenvwrapper" ]]; then
12+  virtualenvwrapper="/etc/bash_completion.d/virtualenvwrapper"
13+  source "/etc/bash_completion.d/virtualenvwrapper"
14+else
15+  print "zsh virtualenvwrapper plugin: Cannot find ${virtualenvwrapper}. Please install with \`pip install virtualenvwrapper\`."
16+  return
17+fi
18 
19+if type workon 2>&1 >/dev/null; then
20   if [[ "$WORKON_HOME" == "" ]]; then
21     echo "\$WORKON_HOME is not defined so ZSH plugin virtualenvwrapper will not work"
22   else
23-
24     if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then
25       # Automatically activate Git projects's virtual environments based on the
26       # directory name of the project. Virtual environment name can be overridden
27@@ -61,5 +68,5 @@ if (( $+commands[$virtualenvwrapper] )); then
28     fi
29   fi
30 else
31-  print "zsh virtualenvwrapper plugin: Cannot find ${virtualenvwrapper}. Please install with \`pip install virtualenvwrapper\`."
32+  print "zsh virtualenvwrapper plugin: shell function 'workon' not defined. Please check ${virtualenvwrapper}." >&2
33 fi