mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-30 02:44:42 +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
|
||||
subdirectories!).
|
||||
- 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"`
|
||||
|
|
|
|||
|
|
@ -87,11 +87,14 @@ function mkv() {
|
|||
if [[ "$PYTHON_AUTO_VRUN" == "true" ]]; then
|
||||
# Automatically activate venv when changing dir
|
||||
auto_vrun() {
|
||||
if [[ -f "${PYTHON_VENV_NAME}/bin/activate" ]]; then
|
||||
source "${PYTHON_VENV_NAME}/bin/activate" > /dev/null 2>&1
|
||||
else
|
||||
(( $+functions[deactivate] )) && deactivate > /dev/null 2>&1
|
||||
fi
|
||||
for activator in "${PYTHON_VENV_NAME}"*/bin/activate(N); do
|
||||
if [[ -f "${activator}" ]]; then
|
||||
source "${activator}" > /dev/null 2>&1
|
||||
return
|
||||
fi
|
||||
done
|
||||
|
||||
(( $+functions[deactivate] )) && deactivate > /dev/null 2>&1
|
||||
}
|
||||
add-zsh-hook chpwd auto_vrun
|
||||
auto_vrun
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue