Diff
1diff --git a/plugins/autoenv/README.md b/plugins/autoenv/README.md
2index de3881774f3f3f4d292a5950600d4a2a73132491..5dfb5fbe81d897dbf4a24c8274a9a1a944d98f7d 100644
3--- a/plugins/autoenv/README.md
4+++ b/plugins/autoenv/README.md
5@@ -7,8 +7,14 @@ To use it, add `autoenv` to the plugins array in your zshrc file:
6 ```zsh
7 plugins=(... autoenv)
8 ```
9+
10+## Functions
11+
12+* `use_env()`: creates and/or activates a virtualenv. For use in `.env` files.
13+ See the source code for details.
14+
15 ## Requirements
16
17 In order to make this work, you will need to have the autoenv installed.
18
19-More info on the usage and install: https://github.com/inishchith/autoenv
20+More info on the usage and install at [the project's homepage](https://github.com/inishchith/autoenv).
21diff --git a/plugins/autoenv/autoenv.plugin.zsh b/plugins/autoenv/autoenv.plugin.zsh
22index 3c1b0fafce8d6471886c1324a52859576e0c4623..bd03cf4b2ba5aed2ab9ad3c8ed3104577b67ded6 100644
23--- a/plugins/autoenv/autoenv.plugin.zsh
24+++ b/plugins/autoenv/autoenv.plugin.zsh
25@@ -1,12 +1,39 @@
26-# Activates autoenv or reports its failure
27+# Initialization: activate autoenv or report its absence
28 () {
29+local d autoenv_dir install_locations
30 if ! type autoenv_init >/dev/null; then
31- for d (~/.autoenv ~/.local/bin /usr/local/opt/autoenv /usr/local/bin); do
32+ # Check if activate.sh is in $PATH
33+ if (( $+commands[activate.sh] )); then
34+ autoenv_dir="${commands[activate.sh]:h}"
35+ fi
36+
37+ # Locate autoenv installation
38+ if [[ -z $autoenv_dir ]]; then
39+ install_locations=(
40+ ~/.autoenv
41+ ~/.local/bin
42+ /usr/local/opt/autoenv
43+ /usr/local/bin
44+ /usr/share/autoenv-git
45+ ~/Library/Python/bin
46+ )
47+ for d ( $install_locations ); do
48+ if [[ -e $d/activate.sh ]]; then
49+ autoenv_dir=$d
50+ break
51+ fi
52+ done
53+ fi
54+
55+ # Look for Homebrew path as a last resort
56+ if [[ -z "$autoenv_dir" ]] && (( $+commands[brew] )); then
57+ d=$(brew --prefix)/opt/autoenv
58 if [[ -e $d/activate.sh ]]; then
59 autoenv_dir=$d
60- break
61 fi
62- done
63+ fi
64+
65+ # Complain if autoenv is not installed
66 if [[ -z $autoenv_dir ]]; then
67 cat <<END >&2
68 -------- AUTOENV ---------
69@@ -17,6 +44,7 @@ In the meantime the autoenv plugin is DISABLED.
70 END
71 return 1
72 fi
73+ # Load autoenv
74 source $autoenv_dir/activate.sh
75 fi
76 }
77@@ -27,17 +55,17 @@ fi
78 # It only performs an action if the requested virtualenv is not the current one.
79
80 use_env() {
81- typeset venv
82- venv="$1"
83- if [[ "${VIRTUAL_ENV:t}" != "$venv" ]]; then
84- if workon | grep -q "$venv"; then
85- workon "$venv"
86- else
87- echo -n "Create virtualenv $venv now? (Yn) "
88- read answer
89- if [[ "$answer" == "Y" ]]; then
90- mkvirtualenv "$venv"
91- fi
92- fi
93+ local venv
94+ venv="$1"
95+ if [[ "${VIRTUAL_ENV:t}" != "$venv" ]]; then
96+ if workon | grep -q "$venv"; then
97+ workon "$venv"
98+ else
99+ echo -n "Create virtualenv $venv now? (Yn) "
100+ read answer
101+ if [[ "$answer" == "Y" ]]; then
102+ mkvirtualenv "$venv"
103+ fi
104 fi
105+ fi
106 }