4b05e548d0b56238521b07dac1969e8cd2dcf608
- Author
- benjaoming <benjaoming@gmail.com>
- Committer
- Benjamin Bach <benjaoming@gmail.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
2index f58bda1ad40a763a733b8532cdd684080bc36173..52e02d3e01390c77f669d2fa657d2b65e7ae5029 100644
3--- a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
4+++ b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
5@@ -1,57 +1,63 @@
6 virtualenvwrapper='virtualenvwrapper.sh'
7 if (( $+commands[$virtualenvwrapper] )); then
8+
9 source ${${virtualenvwrapper}:c}
10
11- if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then
12- # Automatically activate Git projects's virtual environments based on the
13- # directory name of the project. Virtual environment name can be overridden
14- # by placing a .venv file in the project root with a virtualenv name in it
15- function workon_cwd {
16+ if [[ "$WORKON_HOME" == "" ]]; then
17+ echo "\$WORKON_HOME is not defined so ZSH plugin virtualenvwrapper will not work"
18+ else
19+
20+ if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then
21+ # Automatically activate Git projects's virtual environments based on the
22+ # directory name of the project. Virtual environment name can be overridden
23+ # by placing a .venv file in the project root with a virtualenv name in it
24+ function workon_cwd {
25 if [ ! $WORKON_CWD ]; then
26- WORKON_CWD=1
27- # Check if this is a Git repo
28- PROJECT_ROOT=`git rev-parse --show-toplevel 2> /dev/null`
29- if (( $? != 0 )); then
30- PROJECT_ROOT="."
31- fi
32- # Check for virtualenv name override
33- if [[ -f "$PROJECT_ROOT/.venv" ]]; then
34- ENV_NAME=`cat "$PROJECT_ROOT/.venv"`
35- elif [[ -f "$PROJECT_ROOT/.venv/bin/activate" ]];then
36- ENV_NAME="$PROJECT_ROOT/.venv"
37- elif [[ "$PROJECT_ROOT" != "." ]]; then
38- ENV_NAME=`basename "$PROJECT_ROOT"`
39- else
40- ENV_NAME=""
41- fi
42- if [[ "$ENV_NAME" != "" ]]; then
43- # Activate the environment only if it is not already active
44- if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then
45- if [[ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]]; then
46- workon "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME"
47- elif [[ -e "$ENV_NAME/bin/activate" ]]; then
48- source $ENV_NAME/bin/activate && export CD_VIRTUAL_ENV="$ENV_NAME"
49- fi
50- fi
51- elif [ $CD_VIRTUAL_ENV ]; then
52- # We've just left the repo, deactivate the environment
53- # Note: this only happens if the virtualenv was activated automatically
54- deactivate && unset CD_VIRTUAL_ENV
55+ WORKON_CWD=1
56+ # Check if this is a Git repo
57+ PROJECT_ROOT=`git rev-parse --show-toplevel 2> /dev/null`
58+ if (( $? != 0 )); then
59+ PROJECT_ROOT="."
60+ fi
61+ # Check for virtualenv name override
62+ if [[ -f "$PROJECT_ROOT/.venv" ]]; then
63+ ENV_NAME=`cat "$PROJECT_ROOT/.venv"`
64+ elif [[ -f "$PROJECT_ROOT/.venv/bin/activate" ]];then
65+ ENV_NAME="$PROJECT_ROOT/.venv"
66+ elif [[ "$PROJECT_ROOT" != "." ]]; then
67+ ENV_NAME=`basename "$PROJECT_ROOT"`
68+ else
69+ ENV_NAME=""
70+ fi
71+ if [[ "$ENV_NAME" != "" ]]; then
72+ # Activate the environment only if it is not already active
73+ if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then
74+ if [[ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]]; then
75+ workon "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME"
76+ elif [[ -e "$ENV_NAME/bin/activate" ]]; then
77+ source $ENV_NAME/bin/activate && export CD_VIRTUAL_ENV="$ENV_NAME"
78+ fi
79 fi
80- unset PROJECT_ROOT
81- unset WORKON_CWD
82+ elif [ $CD_VIRTUAL_ENV ]; then
83+ # We've just left the repo, deactivate the environment
84+ # Note: this only happens if the virtualenv was activated automatically
85+ deactivate && unset CD_VIRTUAL_ENV
86+ fi
87+ unset PROJECT_ROOT
88+ unset WORKON_CWD
89 fi
90- }
91+ }
92
93- # Append workon_cwd to the chpwd_functions array, so it will be called on cd
94- # http://zsh.sourceforge.net/Doc/Release/Functions.html
95- # TODO: replace with 'add-zsh-hook chpwd workon_cwd' when oh-my-zsh min version is raised above 4.3.4
96- if (( ${+chpwd_functions} )); then
97+ # Append workon_cwd to the chpwd_functions array, so it will be called on cd
98+ # http://zsh.sourceforge.net/Doc/Release/Functions.html
99+ # TODO: replace with 'add-zsh-hook chpwd workon_cwd' when oh-my-zsh min version is raised above 4.3.4
100+ if (( ${+chpwd_functions} )); then
101 if (( $chpwd_functions[(I)workon_cwd] == 0 )); then
102- set -A chpwd_functions $chpwd_functions workon_cwd
103+ set -A chpwd_functions $chpwd_functions workon_cwd
104 fi