mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-16 02:27:03 +01:00
Change auto-venv to be opt-in
This commit is contained in:
parent
d8eab422e1
commit
12163f32e9
2 changed files with 26 additions and 15 deletions
|
|
@ -22,7 +22,9 @@ plugins=(... python)
|
||||||
|
|
||||||
## Virtual environments
|
## Virtual environments
|
||||||
|
|
||||||
The plugin provides three utilities to manage Python venvs:
|
The plugin provides three utilities to manage Python 3.3+
|
||||||
|
[venv](https://docs.python.org/3/library/venv.html) virtual
|
||||||
|
environments:
|
||||||
|
|
||||||
- `mkv [name]`: make a new virtual environment called `name` (default: `venv`) in current directory.
|
- `mkv [name]`: make a new virtual environment called `name` (default: `venv`) in current directory.
|
||||||
|
|
||||||
|
|
@ -30,10 +32,21 @@ The plugin provides three utilities to manage Python venvs:
|
||||||
|
|
||||||
- `auto_vrun`: Automatically activate the venv virtual environment when
|
- `auto_vrun`: Automatically activate the venv virtual environment when
|
||||||
cd’ing into a directory containing `venv/bin/activate`, and
|
cd’ing into a directory containing `venv/bin/activate`, and
|
||||||
automatically deactivate the venv virtual environment when cd’ing into
|
automatically deactivate it when cd’ing into any other directory,
|
||||||
any other directory.
|
including subdirectories.
|
||||||
- Set the environment variable `VENV_NAME` to auto-activate on a
|
- To enable, set `PYTHON_AUTO_VRUN` to anything. For example:
|
||||||
different venv name. (Example: `VENV_NAME=.venv`).
|
|
||||||
- Set the environment variable `DISABLE_AUTO_VRUN` to anything to
|
export PYTHON_AUTO_VRUN='true'
|
||||||
deactivate `auto_vrun`. (Example: `DISABLE_AUTO_VRUN=true`) Unset
|
- To disable, either unset the environment variable:
|
||||||
`DISABLE_AUTO_VRUN` to re-enable.
|
|
||||||
|
unset PYTHON_AUTO_VRUN
|
||||||
|
or entirely remove `auto_vrun` from the list of functions associated
|
||||||
|
with the `chpwd` hook:
|
||||||
|
|
||||||
|
add-zsh-hook -d chpwd auto_vrun
|
||||||
|
If you disable `auto_vrun` while a virtual environment is active,
|
||||||
|
you'll need to manually `deactivate`.
|
||||||
|
- The default virtual environment name is "venv". To use a different
|
||||||
|
name, set `PYTHON_VENV_NAME`. For example:
|
||||||
|
|
||||||
|
export PYTHON_VENV_NAME='.venv'
|
||||||
|
|
|
||||||
|
|
@ -82,16 +82,14 @@ function mkv() {
|
||||||
vrun "${name}"
|
vrun "${name}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Virtual environment is assumed to be named "venv".
|
# Automatically activate venv when cd'ing into a directory
|
||||||
# Set VENV_NAME to another name if you use a different name, maybe ".venv".
|
|
||||||
# To disable, set DISABLE_AUTO_VRUN to anything. Unset to re-enable.
|
|
||||||
auto_vrun() {
|
auto_vrun() {
|
||||||
[ $DISABLE_AUTO_VRUN ] && return 0
|
[[ ! -n "$PYTHON_AUTO_VRUN" ]] && return 0
|
||||||
local venvpath=${VENV_NAME:-'venv'}
|
local venvpath="${PYTHON_VENV_NAME:-venv}"
|
||||||
if [ -e "${venvpath}/bin/activate" ]; then
|
if [[ -f "${venvpath}/bin/activate" ]]; then
|
||||||
source "${venvpath}/bin/activate" > /dev/null 2>&1
|
source "${venvpath}/bin/activate" > /dev/null 2>&1
|
||||||
else
|
else
|
||||||
[ -n "$(command -v deactivate)" ] && deactivate > /dev/null 2>&1
|
[[ -n "$(command -v deactivate)" ]] && deactivate > /dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
add-zsh-hook chpwd auto_vrun
|
add-zsh-hook chpwd auto_vrun
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue