better impl

This commit is contained in:
Carlo Sala 2024-05-07 21:28:49 +02:00
commit 9d99b97a7d
No known key found for this signature in database
GPG key ID: DA6FB450C1A4FE9A

View file

@ -87,21 +87,20 @@ 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
function auto_vrun() { function auto_vrun() {
local dirname="$PWD" # 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
while if [[ $PWD != ${VIRTUAL_ENV:h} ]]; then
for activator in "${dirname}/${PYTHON_VENV_NAME}"*/bin/activate(N); do for _file in "${PYTHON_VENV_NAME}"*/bin/activate(N.); do
if [[ -f "${activator}" ]]; then # make sure we're not in a venv already
source "${activator}" > /dev/null 2>&1 (( $+functions[deactivate] )) && deactivate > /dev/null 2>&1
return source $_file > /dev/null 2>&1
fi break
done done
[[ -n "$dirname" ]] fi
do
dirname=${dirname%/*}
done
(( $+functions[deactivate] )) && deactivate > /dev/null 2>&1
} }
add-zsh-hook chpwd auto_vrun add-zsh-hook chpwd auto_vrun
auto_vrun auto_vrun