oh-my-zsh/plugins/autoenv/autoenv.plugin.zsh
Adrian Petrescu 9263e9ca59 Add /usr/local/bin to autoenv search path (#5481)
The current list of directories to search for autoenv on misses the default location on Ubuntu systems if you just do a normal `pip install autoenv` - [it will place](https://github.com/kennethreitz/autoenv/blob/master/setup.py#L16) `activate.sh` in `/usr/local/bin` unless you manually override the `--prefix` or something.

The `/usr/local/opt/autoenv` is fine for macOS/homebrew installations but it would be nice not to have to manually patch on Linux :)
2016-09-30 23:39:32 +02:00

44 lines
1.2 KiB
Bash

# Activates autoenv or reports its failure
() {
if ! type autoenv_init >/dev/null; then
for d (~/.autoenv /usr/local/opt/autoenv /usr/local/bin); do
if [[ -e $d/activate.sh ]]; then
autoenv_dir=$d
break
fi
done
if [[ -z $autoenv_dir ]]; then
cat <<END >&2
-------- AUTOENV ---------
Could not locate autoenv installation.
Please check if autoenv is correctly installed.
In the meantime the autoenv plugin is DISABLED.
--------------------------
END
return 1
fi
source $autoenv_dir/activate.sh
fi
}
[[ $? != 0 ]] && return $?
# The use_env call below is a reusable command to activate/create a new Python
# virtualenv, requiring only a single declarative line of code in your .env files.
# 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
fi
}