ef4e2aa26def9451eccb12bd31955c1d08e56348

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Merge pull request #1293 from cenkalti/master

Look virtualenvwrapper plugin in PATH

Diff

 1diff --git a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
 2index 5d0860400a0d83bd98912a7bd1a7470f6031a5b8..a5abb77c3f26a9e0ac6b664f483471090be602e9 100644
 3--- a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
 4+++ b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
 5@@ -1,46 +1,40 @@
 6-WRAPPER_FOUND=0
 7-for wrapsource in "/usr/bin/virtualenvwrapper.sh" "/usr/local/bin/virtualenvwrapper.sh" "/etc/bash_completion.d/virtualenvwrapper" ; do
 8-  if [[ -e $wrapsource ]] ; then
 9-    WRAPPER_FOUND=1
10-    source $wrapsource
11+wrapsource=`which virtualenvwrapper.sh`
12 
13-    if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then
14-      # Automatically activate Git projects' virtual environments based on the
15-      # directory name of the project. Virtual environment name can be overridden
16-      # by placing a .venv file in the project root with a virtualenv name in it
17-      function workon_cwd {
18-          # Check that this is a Git repo
19-          PROJECT_ROOT=`git rev-parse --show-toplevel 2> /dev/null`
20-          if (( $? == 0 )); then
21-              # Check for virtualenv name override
22-              ENV_NAME=`basename "$PROJECT_ROOT"`
23-              if [[ -f "$PROJECT_ROOT/.venv" ]]; then
24-                  ENV_NAME=`cat "$PROJECT_ROOT/.venv"`
25-              fi
26-              # Activate the environment only if it is not already active
27-              if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then
28-                  if [[ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]]; then
29-                      workon "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME"
30-                  fi
31-              fi
32-          elif [ $CD_VIRTUAL_ENV ]; then
33-              # We've just left the repo, deactivate the environment
34-              # Note: this only happens if the virtualenv was activated automatically
35-              deactivate && unset CD_VIRTUAL_ENV
36-          fi
37-          unset PROJECT_ROOT
38-      }
39+if [[ -f "$wrapsource" ]]; then
40+  source $wrapsource
41 
42-      # New cd function that does the virtualenv magic
43-      function cd {
44-          builtin cd "$@" && workon_cwd
45-      }
46-    fi
47+  if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then
48+    # Automatically activate Git projects' virtual environments based on the
49+    # directory name of the project. Virtual environment name can be overridden
50+    # by placing a .venv file in the project root with a virtualenv name in it
51+    function workon_cwd {
52+        # Check that this is a Git repo
53+        PROJECT_ROOT=`git rev-parse --show-toplevel 2> /dev/null`
54+        if (( $? == 0 )); then
55+            # Check for virtualenv name override
56+            ENV_NAME=`basename "$PROJECT_ROOT"`
57+            if [[ -f "$PROJECT_ROOT/.venv" ]]; then
58+                ENV_NAME=`cat "$PROJECT_ROOT/.venv"`
59+            fi
60+            # Activate the environment only if it is not already active
61+            if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then
62+                if [[ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]]; then
63+                    workon "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME"
64+                fi
65+            fi
66+        elif [ $CD_VIRTUAL_ENV ]; then
67+            # We've just left the repo, deactivate the environment
68+            # Note: this only happens if the virtualenv was activated automatically
69+            deactivate && unset CD_VIRTUAL_ENV
70+        fi
71+        unset PROJECT_ROOT
72+    }
73 
74-    break
75+    # New cd function that does the virtualenv magic
76+    function cd {
77+        builtin cd "$@" && workon_cwd
78+    }
79   fi
80-done
81-
82-if [ $WRAPPER_FOUND -eq 0 ] ; then
83-  print "zsh virtualenvwrapper plugin: Couldn't activate virtualenvwrapper. Please run \`pip install virtualenvwrapper\`."
84+else
85+  print "zsh virtualenvwrapper plugin: Cannot find virtualenvwrapper.sh. Please install with \`pip install virtualenvwrapper\`."
86 fi