Skip to content

Commit c4cbcd6

Browse files
committed
hooks(feat): add warning for set_hooks on tmux < 3.0
why: Hook arrays are a tmux 3.0+ feature. On tmux < 3.0, hooks are stored by exact name in a red-black tree, so "session-renamed[0]" is a literal hook name, not an array index. This causes unexpected behavior with set_hooks and clear_existing. what: - Add UserWarning when set_hooks is called on tmux < 3.0 - Warning explains the limitation and references tmux commit dfb7bb68 Ref: tmux commit dfb7bb68 (April 2019) merged hooks into options as array options for tmux 3.0.
1 parent edfbf5f commit c4cbcd6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/libtmux/hooks.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,18 @@ def set_hooks(
483483
>>> session.unset_hook('after-new-window') # doctest: +SKIP
484484
Session($...)
485485
"""
486+
# Hook arrays require tmux 3.0+. On older versions, hooks are stored
487+
# by exact name (e.g. "session-renamed[0]" is a literal name, not an
488+
# array index). See tmux commit dfb7bb68 (April 2019).
489+
if has_lt_version("3.0"):
490+
warnings.warn(
491+
"Hook arrays require tmux 3.0+. "
492+
"On older versions, set_hooks creates hooks with literal bracket "
493+
"names (e.g. 'session-renamed[0]') instead of array indices, "
494+
"and clear_existing/unset_hook may not work as expected.",
495+
stacklevel=2,
496+
)
497+
486498
if clear_existing:
487499
self.unset_hook(hook, global_=global_, scope=scope)
488500

0 commit comments

Comments
 (0)