diff options
| author | Michael Gonzo <feasuro@protonmail.com> | 2024-05-07 21:30:23 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-07 21:30:23 +0200 |
| commit | 22bbc233e90f18ad7a02625c66d1867a5486fcbb (patch) | |
| tree | 5148b5ffae851402bccbed0fbcd2b58ab22923d3 /plugins/python/python.plugin.zsh | |
| parent | 668ca3a32dae5ff5d164fc3be565f1e2ece248db (diff) | |
| download | zsh-22bbc233e90f18ad7a02625c66d1867a5486fcbb.tar.gz zsh-22bbc233e90f18ad7a02625c66d1867a5486fcbb.tar.bz2 zsh-22bbc233e90f18ad7a02625c66d1867a5486fcbb.zip | |
feat(python): autovenv keeps activated on subdirs (#12396)
Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
Diffstat (limited to 'plugins/python/python.plugin.zsh')
| -rw-r--r-- | plugins/python/python.plugin.zsh | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/plugins/python/python.plugin.zsh b/plugins/python/python.plugin.zsh index f6ea85027..7256aa04f 100644 --- a/plugins/python/python.plugin.zsh +++ b/plugins/python/python.plugin.zsh @@ -86,11 +86,20 @@ 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 + function auto_vrun() { + # deactivate if we're on a different dir than VIRTUAL_ENV states + # we don't deactivate subdirectories! + if (( $+functions[deactivate] )) && [[ $PWD != ${VIRTUAL_ENV:h}* ]]; then + deactivate > /dev/null 2>&1 + fi + + if [[ $PWD != ${VIRTUAL_ENV:h} ]]; then + for _file in "${PYTHON_VENV_NAME}"*/bin/activate(N.); do + # make sure we're not in a venv already + (( $+functions[deactivate] )) && deactivate > /dev/null 2>&1 + source $_file > /dev/null 2>&1 + break + done fi } add-zsh-hook chpwd auto_vrun |
