diff options
| author | 2026-05-19 15:16:10 +0100 | |
|---|---|---|
| committer | 2026-05-19 15:16:10 +0100 | |
| commit | 2fa5bfcb240552d7787911ae2c29e71c5058246a (patch) | |
| tree | 2d4d025f28d3bf1690d6d3a85d159b3bb5a07c24 /dot_config/zsh | |
| parent | c4453276b9c351094ce247150918a2dd50429881 (diff) | |
| download | dotfiles-2fa5bfcb240552d7787911ae2c29e71c5058246a.tar.gz dotfiles-2fa5bfcb240552d7787911ae2c29e71c5058246a.tar.bz2 dotfiles-2fa5bfcb240552d7787911ae2c29e71c5058246a.zip | |
fix(zsh): only rename zellij tab when our pane is focused
`zellij action rename-tab` always targets the focused tab — there is
no CLI way to bind the rename to the calling pane. On session
resurrect zellij re-spawns every shell almost simultaneously while one
tab is focused, so every precmd hook fires and they all race to
rename that single focused tab; the last writer wins and the rest of
the tabs are stuck at `Tab #N`. This is the "all tabs got the same
label" bug from earlier.
Guard the rename hooks behind a focused-pane check using
`zellij action list-clients` (matches the `terminal_<ZELLIJ_PANE_ID>`
column). Background panes silently skip the rename and update lazily
the next time the user focuses them and a prompt fires. After
resurrect that means untouched tabs say `Tab #N` until you visit
them — but no tab gets a wrong label anymore.
Diffstat (limited to 'dot_config/zsh')
| -rw-r--r-- | dot_config/zsh/dot_zshrc | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/dot_config/zsh/dot_zshrc b/dot_config/zsh/dot_zshrc index 27daa2c..faf538b 100644 --- a/dot_config/zsh/dot_zshrc +++ b/dot_config/zsh/dot_zshrc @@ -163,13 +163,25 @@ fi # immutable creation index, not the live position) and never updates when # tabs are closed or moved — so the default is actively misleading. We rename # to `dir:cmd` from the shell hooks; position is implied by visual order in -# the tab bar. Untouched tabs after a resurrect or after closing a middle tab -# will still show their previous dir:cmd until the next prompt fires there, -# but at least there's no wrong *number* attached. +# the tab bar. +# +# `zellij action rename-tab` always targets the *focused* tab (no way to +# target by pane id from the CLI), and on session resurrect every shell +# fires precmd nearly simultaneously while one tab is focused — without a +# guard, every pane would rename that one tab and the last writer wins, +# leaving every other tab stuck at "Tab #N". So we only rename when our +# pane is currently focused. Background panes' labels update lazily the +# next time the user focuses them and triggers a prompt. if [[ -n "$ZELLIJ" ]]; then _zellij_dir() { [[ "$PWD" == "$HOME" ]] && echo '~' || echo "${PWD##*/}"; } - _zellij_tab_precmd() { zellij action rename-tab "$(_zellij_dir)" 2>/dev/null; } - _zellij_tab_preexec() { zellij action rename-tab "$(_zellij_dir):${1%% *}" 2>/dev/null; } + _zellij_is_focused_pane() { + [[ -n $ZELLIJ_PANE_ID ]] || return 1 + local focused + focused=$(zellij action list-clients 2>/dev/null | awk 'NR>1 {print $2}') + [[ -n $focused ]] && print -r -- "$focused" | grep -qx "terminal_${ZELLIJ_PANE_ID}" + } + _zellij_tab_precmd() { _zellij_is_focused_pane && zellij action rename-tab "$(_zellij_dir)" 2>/dev/null; } + _zellij_tab_preexec() { _zellij_is_focused_pane && zellij action rename-tab "$(_zellij_dir):${1%% *}" 2>/dev/null; } add-zsh-hook precmd _zellij_tab_precmd add-zsh-hook preexec _zellij_tab_preexec fi |
