summaryrefslogtreecommitdiff
path: root/plugins/autoenv
diff options
context:
space:
mode:
authorAndrew Janke <andrew@apjanke.net>2015-12-18 18:45:17 -0500
committerMarc Cornellà <marc.cornella@live.com>2020-03-12 16:48:31 +0100
commit58e38155fc4342be1721f0b7b30f1e112fe38e93 (patch)
tree5bbee51b6766a64d416314f314fc95fa82eaba19 /plugins/autoenv
parent610b2529d2213a70e3d1153a9baf046c22f298b9 (diff)
downloadzsh-58e38155fc4342be1721f0b7b30f1e112fe38e93.tar.gz
zsh-58e38155fc4342be1721f0b7b30f1e112fe38e93.tar.bz2
zsh-58e38155fc4342be1721f0b7b30f1e112fe38e93.zip
autoenv: look in additional installation locations, redo logic
Fixes #4681 Co-authored-by: Marc Cornellà <marc.cornella@live.com>
Diffstat (limited to 'plugins/autoenv')
-rw-r--r--plugins/autoenv/README.md8
-rw-r--r--plugins/autoenv/autoenv.plugin.zsh60
2 files changed, 51 insertions, 17 deletions
diff --git a/plugins/autoenv/README.md b/plugins/autoenv/README.md
index de3881774..5dfb5fbe8 100644
--- a/plugins/autoenv/README.md
+++ b/plugins/autoenv/README.md
@@ -7,8 +7,14 @@ To use it, add `autoenv` to the plugins array in your zshrc file:
```zsh
plugins=(... autoenv)
```
+
+## Functions
+
+* `use_env()`: creates and/or activates a virtualenv. For use in `.env` files.
+ See the source code for details.
+
## Requirements
In order to make this work, you will need to have the autoenv installed.
-More info on the usage and install: https://github.com/inishchith/autoenv
+More info on the usage and install at [the project's homepage](https://github.com/inishchith/autoenv).
diff --git a/plugins/autoenv/autoenv.plugin.zsh b/plugins/autoenv/autoenv.plugin.zsh
index 3c1b0fafc..bd03cf4b2 100644
--- a/plugins/autoenv/autoenv.plugin.zsh
+++ b/plugins/autoenv/autoenv.plugin.zsh
@@ -1,12 +1,39 @@
-# Activates autoenv or reports its failure
+# Initialization: activate autoenv or report its absence
() {
+local d autoenv_dir install_locations
if ! type autoenv_init >/dev/null; then
- for d (~/.autoenv ~/.local/bin /usr/local/opt/autoenv /usr/local/bin); do
+ # Check if activate.sh is in $PATH
+ if (( $+commands[activate.sh] )); then
+ autoenv_dir="${commands[activate.sh]:h}"
+ fi
+
+ # Locate autoenv installation
+ if [[ -z $autoenv_dir ]]; then
+ install_locations=(
+ ~/.autoenv
+ ~/.local/bin
+ /usr/local/opt/autoenv
+ /usr/local/bin
+ /usr/share/autoenv-git
+ ~/Library/Python/bin
+ )
+ for d ( $install_locations ); do
+ if [[ -e $d/activate.sh ]]; then
+ autoenv_dir=$d
+ break
+ fi
+ done
+ fi
+
+ # Look for Homebrew path as a last resort
+ if [[ -z "$autoenv_dir" ]] && (( $+commands[brew] )); then
+ d=$(brew --prefix)/opt/autoenv
if [[ -e $d/activate.sh ]]; then
autoenv_dir=$d
- break
fi
- done
+ fi
+
+ # Complain if autoenv is not installed
if [[ -z $autoenv_dir ]]; then
cat <<END >&2
-------- AUTOENV ---------
@@ -17,6 +44,7 @@ In the meantime the autoenv plugin is DISABLED.
END
return 1
fi
+ # Load autoenv
source $autoenv_dir/activate.sh
fi
}
@@ -27,17 +55,17 @@ fi
# It only performs an action if the requested virtualenv is not the current one.
use_env() {
- typeset venv
- venv="$1"
- if [[ "${VIRTUAL_ENV:t}" != "$venv" ]]; then
- if workon | grep -q "$venv"; then
- workon "$venv"
- else
- echo -n "Create virtualenv $venv now? (Yn) "
- read answer
- if [[ "$answer" == "Y" ]]; then
- mkvirtualenv "$venv"
- fi
- fi
+ local venv
+ venv="$1"
+ if [[ "${VIRTUAL_ENV:t}" != "$venv" ]]; then
+ if workon | grep -q "$venv"; then
+ workon "$venv"
+ else
+ echo -n "Create virtualenv $venv now? (Yn) "
+ read answer
+ if [[ "$answer" == "Y" ]]; then
+ mkvirtualenv "$venv"
+ fi
fi
+ fi
}