[TMUX/ZSH] Venv improvements

This commit is contained in:
Fabian Ising
2026-07-16 14:25:28 +02:00
parent 5251ee0f84
commit a0ef696325
4 changed files with 55 additions and 5 deletions
+17 -3
View File
@@ -10,6 +10,20 @@ export VIRTUALENVWRAPPER_VIRTUALENV=$PREFIX/bin/virtualenv
mkdir -p $WORKON_HOME
source $PREFIX/bin/virtualenvwrapper.sh
if [ -n "$VIRTUAL_ENV" ] && [[ -f "$VIRTUAL_ENV/bin/activate" ]]; then
source $VIRTUAL_ENV/bin/activate;
fi
# NOTE: an inherited VIRTUAL_ENV is *not* re-activated here — that happens at the
# very end of .zshrc so activate captures the fully-built PATH (see the comment
# there). Sourcing virtualenvwrapper.sh above only defines workon/deactivate/etc.
# Mirror the current venv into a per-pane tmux option so that splitting a pane
# can carry it into the new pane (.tmux.conf reads #{@venv} with `-e`). Per-pane
# (not session) state is what lets two panes hold different venvs and lets new
# *windows* start clean. Only fork tmux when the value actually changes.
_venv_track_precmd() {
[[ -n $TMUX ]] || return
if [[ "${VIRTUAL_ENV:-}" != "${_LAST_TRACKED_VENV-unset}" ]]; then
tmux set -p @venv "${VIRTUAL_ENV:-}" 2>/dev/null
_LAST_TRACKED_VENV="${VIRTUAL_ENV:-}"
fi
}
autoload -Uz add-zsh-hook
add-zsh-hook precmd _venv_track_precmd