mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-12-05 01:46:46 +01:00
feat(python): autovenv keeps activated on subdirs (#12396)
Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
This commit is contained in:
parent
668ca3a32d
commit
22bbc233e9
2 changed files with 18 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue