mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-13 03:01:32 +01:00
feat(python): pattern matching in auto_vrun
This commit is contained in:
parent
668ca3a32d
commit
26b3467806
2 changed files with 10 additions and 6 deletions
|
|
@ -35,5 +35,6 @@ virtual environments:
|
||||||
`<venv-name>/bin/activate`, and automatically deactivate it when navigating out of it (including
|
`<venv-name>/bin/activate`, and automatically deactivate it when navigating out of it (including
|
||||||
subdirectories!).
|
subdirectories!).
|
||||||
- To enable the feature, set `export PYTHON_AUTO_VRUN=true` before sourcing oh-my-zsh.
|
- To enable the feature, set `export PYTHON_AUTO_VRUN=true` before sourcing oh-my-zsh.
|
||||||
- The default virtual environment name is `venv`. To use a different name, set
|
- Plugin activates first virtual environment in lexicographic order whose name begins with `<venv-name>`.
|
||||||
|
The default virtual environment name is `venv`. To use a different name, set
|
||||||
`export PYTHON_VENV_NAME=<venv-name>`. For example: `export PYTHON_VENV_NAME=".venv"`
|
`export PYTHON_VENV_NAME=<venv-name>`. For example: `export PYTHON_VENV_NAME=".venv"`
|
||||||
|
|
|
||||||
|
|
@ -87,11 +87,14 @@ function mkv() {
|
||||||
if [[ "$PYTHON_AUTO_VRUN" == "true" ]]; then
|
if [[ "$PYTHON_AUTO_VRUN" == "true" ]]; then
|
||||||
# Automatically activate venv when changing dir
|
# Automatically activate venv when changing dir
|
||||||
auto_vrun() {
|
auto_vrun() {
|
||||||
if [[ -f "${PYTHON_VENV_NAME}/bin/activate" ]]; then
|
for activator in "${PYTHON_VENV_NAME}"*/bin/activate(N); do
|
||||||
source "${PYTHON_VENV_NAME}/bin/activate" > /dev/null 2>&1
|
if [[ -f "${activator}" ]]; then
|
||||||
else
|
source "${activator}" > /dev/null 2>&1
|
||||||
(( $+functions[deactivate] )) && deactivate > /dev/null 2>&1
|
return
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
(( $+functions[deactivate] )) && deactivate > /dev/null 2>&1
|
||||||
}
|
}
|
||||||
add-zsh-hook chpwd auto_vrun
|
add-zsh-hook chpwd auto_vrun
|
||||||
auto_vrun
|
auto_vrun
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue