6aa9720b4bfdb1fd909ff09c8c422968aeb5af4c
- Author
- Robby Russell <robby@planetargon.com>
- Committer
- Robby Russell <robby@planetargon.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 217ab0722dd3cb022ba9fa8bf8226629c58ab713..5faa1a823aa7c9764aef2eb95aed5fa16a5e3bb4 100644
3--- a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
4+++ b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
5@@ -1,65 +1,70 @@
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}.\n"\
16+ "Please install with \`pip install virtualenvwrapper\`" >&2
17+ return
18+fi
19+if ! type workon &>/dev/null; then
20+ print "zsh virtualenvwrapper plugin: shell function 'workon' not defined.\n"\
21+ "Please check ${virtualenvwrapper}" >&2
22+ return
23+fi
24
25- if [[ "$WORKON_HOME" == "" ]]; then
26- echo "\$WORKON_HOME is not defined so ZSH plugin virtualenvwrapper will not work"
27- else
28+if [[ "$WORKON_HOME" == "" ]]; then
29+ print "\$WORKON_HOME is not defined so ZSH plugin virtualenvwrapper will not work" >&2
30+ return
31+fi
32
33- if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then
34- # Automatically activate Git projects's virtual environments based on the
35- # directory name of the project. Virtual environment name can be overridden
36- # by placing a .venv file in the project root with a virtualenv name in it
37- function workon_cwd {
38- if [ ! $WORKON_CWD ]; then
39- WORKON_CWD=1
40- # Check if this is a Git repo
41- PROJECT_ROOT=`git rev-parse --show-toplevel 2> /dev/null`
42- if (( $? != 0 )); then
43- PROJECT_ROOT="."
44- fi
45- # Check for virtualenv name override
46- if [[ -f "$PROJECT_ROOT/.venv" ]]; then
47- ENV_NAME=`cat "$PROJECT_ROOT/.venv"`
48- elif [[ -f "$PROJECT_ROOT/.venv/bin/activate" ]];then
49- ENV_NAME="$PROJECT_ROOT/.venv"
50- elif [[ "$PROJECT_ROOT" != "." ]]; then
51- ENV_NAME=`basename "$PROJECT_ROOT"`
52- else
53- ENV_NAME=""
54- fi
55- if [[ "$ENV_NAME" != "" ]]; then
56- # Activate the environment only if it is not already active
57- if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then
58- if [[ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]]; then
59- workon "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME"
60- elif [[ -e "$ENV_NAME/bin/activate" ]]; then
61- source $ENV_NAME/bin/activate && export CD_VIRTUAL_ENV="$ENV_NAME"
62- fi
63- fi
64- elif [[ -n $CD_VIRTUAL_ENV && -n $VIRTUAL_ENV ]]; then
65- # We've just left the repo, deactivate the environment
66- # Note: this only happens if the virtualenv was activated automatically
67- deactivate && unset CD_VIRTUAL_ENV
68+if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then
69+ # Automatically activate Git projects's virtual environments based on the
70+ # directory name of the project. Virtual environment name can be overridden
71+ # by placing a .venv file in the project root with a virtualenv name in it
72+ function workon_cwd {
73+ if [ ! $WORKON_CWD ]; then
74+ WORKON_CWD=1
75+ # Check if this is a Git repo
76+ PROJECT_ROOT=`git rev-parse --show-toplevel 2> /dev/null`
77+ if (( $? != 0 )); then
78+ PROJECT_ROOT="."
79+ fi
80+ # Check for virtualenv name override
81+ if [[ -f "$PROJECT_ROOT/.venv" ]]; then
82+ ENV_NAME=`cat "$PROJECT_ROOT/.venv"`
83+ elif [[ -f "$PROJECT_ROOT/.venv/bin/activate" ]];then
84+ ENV_NAME="$PROJECT_ROOT/.venv"
85+ elif [[ "$PROJECT_ROOT" != "." ]]; then
86+ ENV_NAME=`basename "$PROJECT_ROOT"`
87+ else
88+ ENV_NAME=""
89+ fi
90+ if [[ "$ENV_NAME" != "" ]]; then
91+ # Activate the environment only if it is not already active
92+ if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then
93+ if [[ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]]; then
94+ workon "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME"
95+ elif [[ -e "$ENV_NAME/bin/activate" ]]; then
96+ source $ENV_NAME/bin/activate && export CD_VIRTUAL_ENV="$ENV_NAME"
97 fi
98- unset PROJECT_ROOT
99- unset WORKON_CWD
100- fi
101- }
102-
103- # Append workon_cwd to the chpwd_functions array, so it will be called on cd
104- # http://zsh.sourceforge.net/Doc/Release/Functions.html