diff --git a/.local/bin/tmux-window-icons b/.local/bin/tmux-window-icons new file mode 100755 index 0000000..14d55b5 --- /dev/null +++ b/.local/bin/tmux-window-icons @@ -0,0 +1,24 @@ +#!/bin/bash +# Stamp every window with its circled-number icon as a WINDOW-level user option. +# +# Why not do this in the format string: the obvious approach nests ten +# #{?#{==:#{window_index},N},...} conditionals, which tmux re-evaluates for +# every window on every redraw -- and redraws are driven by PANE ACTIVITY, so a +# busy pane re-runs all ten per window, several times a second. +# +# Here the work happens ONCE per window change (driven by hooks) and the render +# path becomes #{@icon}: a plain variable lookup, no conditionals, no forks. +# +# Do NOT call this from the status format itself -- that would make it a #() +# job, which renders EMPTY while restarting and is the original bug. +symbols=(❶ ❷ ❸ ❹ ❺ ❻ ❼ ❽ ❾ ❿) +while IFS= read -r w; do + idx=${w##*:} + [[ $idx =~ ^[0-9]+$ ]] || continue + if (( idx >= 1 && idx <= ${#symbols[@]} )); then + icon=${symbols[idx-1]} + else + icon=$idx + fi + tmux set -w -t "$w" @icon "$icon" 2>/dev/null +done < <(tmux list-windows -a -F '#{session_name}:#{window_index}' 2>/dev/null)