Merge pull request #1877 from spazm/virtualenvwrapper-cleanup
virtualenvwrapper plugin cleanup
Diff
1diff --git a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
2index 35de508746ad21f31290cbac98861b5b3fcc7c3c..670c287bd425d7b9616866d03f0832c1776d992e 100644
3--- a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
4+++ b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
5@@ -1,10 +1,9 @@
6-wrapsource=`which virtualenvwrapper_lazy.sh`
7-
8-if [[ -f "$wrapsource" ]]; then
9- source $wrapsource
10+virtualenvwrapper='virtualenvwrapper_lazy.sh'
11+if (( $+commands[$virtualenvwrapper] )); then
12+ source ${${virtualenvwrapper}:c}
1314 if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then
15- # Automatically activate Git projects' virtual environments based on the
16+ # Automatically activate Git projects's virtual environments based on the
17 # directory name of the project. Virtual environment name can be overridden
18 # by placing a .venv file in the project root with a virtualenv name in it
19 function workon_cwd {
20@@ -40,11 +39,17 @@ if [[ -f "$wrapsource" ]]; then
21 fi
22 }
2324- # New cd function that does the virtualenv magic
25- function cd {
26- builtin cd "$@" && workon_cwd
27- }
28+ # Append workon_cwd to the chpwd_functions array, so it will be called on cd
29+ # http://zsh.sourceforge.net/Doc/Release/Functions.html
30+ # TODO: replace with 'add-zsh-hook chpwd workon_cwd' when oh-my-zsh min version is raised above 4.3.4
31+ if (( ${+chpwd_functions} )); then
32+ if (( $chpwd_functions[(I)workon_cwd] == 0 )); then
33+ set -A chpwd_functions $chpwd_functions workon_cwd
34+ fi
35+ else
36+ set -A chpwd_functions workon_cwd
37+ fi
38 fi
39 else
40- print "zsh virtualenvwrapper plugin: Cannot find virtualenvwrapper_lazy.sh. Please install with \`pip install virtualenvwrapper\`."
41+ print "zsh virtualenvwrapper plugin: Cannot find ${virtualenvwrapper}. Please install with \`pip install virtualenvwrapper\`."
42 fi