feat(python): pattern matching in auto_vrun

This commit is contained in:
Feasuro 2024-05-04 15:35:05 +02:00
commit 26b3467806
No known key found for this signature in database
GPG key ID: 4EB3F9F0ED4AD469
2 changed files with 10 additions and 6 deletions

View file

@ -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"`

View file

@ -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