Skip to content

Commit

Permalink
better impl
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosala committed May 7, 2024
1 parent 1965d1b commit 9d99b97
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions plugins/python/python.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,20 @@ function mkv() {
if [[ "$PYTHON_AUTO_VRUN" == "true" ]]; then
# Automatically activate venv when changing dir
function auto_vrun() {
local dirname="$PWD"

while
for activator in "${dirname}/${PYTHON_VENV_NAME}"*/bin/activate(N); do
if [[ -f "${activator}" ]]; then
source "${activator}" > /dev/null 2>&1
return
fi
# 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
[[ -n "$dirname" ]]
do
dirname=${dirname%/*}
done

(( $+functions[deactivate] )) && deactivate > /dev/null 2>&1
fi
}
add-zsh-hook chpwd auto_vrun
auto_vrun
Expand Down

0 comments on commit 9d99b97

Please sign in to comment.