Core LibrarystableAPI Reference

Choose documentation 3

stable

Current version

stable
English

Prerelease This site documents an alpha of libtmux. Its structure, URLs and APIs are subject to change.

Python API

class libtmux stable

Hooks

tmux hooks data structure.

Source and package
Qualified name
libtmux._internal.constants.Hooks
Module
libtmux._internal.constants
Package
libtmux
Source
src/libtmux/_internal/constants.py
class libtmux._internal.constants.Hooks

Description#

Parses tmux hook output into typed SparseArray fields, preserving array indices for hooks that can have multiple commands at different indices.

Examples#

Parse raw tmux hook output:

>>> from libtmux._internal.constants import Hooks
>>> raw = [
... "session-renamed[0] set-option -g status-left-style bg=red",
... "session-renamed[1] display-message 'session renamed'",
... ]
>>> hooks = Hooks.from_stdout(raw)

Access individual hook commands by index:

>>> hooks.session_renamed[0]
'set-option -g status-left-style bg=red'
>>> hooks.session_renamed[1]
"display-message 'session renamed'"

Get all commands as a list (sorted by index):

>>> hooks.session_renamed.as_list()
['set-option -g status-left-style bg=red', "display-message 'session renamed'"]

Sparse indices are preserved (gaps in index numbers):

>>> raw_sparse = [
... "pane-focus-in[0] refresh-client",
... "pane-focus-in[5] display-message 'focus'",
... ]
>>> hooks_sparse = Hooks.from_stdout(raw_sparse)
>>> 0 in hooks_sparse.pane_focus_in
True
>>> 5 in hooks_sparse.pane_focus_in
True
>>> 3 in hooks_sparse.pane_focus_in
False
>>> sorted(hooks_sparse.pane_focus_in.keys())
[0, 5]

Iterate over values in index order:

>>> for cmd in hooks_sparse.pane_focus_in.iter_values():
... print(cmd)
refresh-client
display-message 'focus'

Multiple hook types in one parse:

>>> raw_multi = [
... "after-new-window[0] select-pane -t 0",
... "after-new-window[1] send-keys 'clear' Enter",
... "window-renamed[0] refresh-client -S",
... ]
>>> hooks_multi = Hooks.from_stdout(raw_multi)
>>> len(hooks_multi.after_new_window)
2
>>> len(hooks_multi.window_renamed)
1

tmux catalog Hooks

Members91#

Common operations1#

  • from_stdout method Parse raw tmux hook output into a Hooks instance.

Other members90#

Inherited members1 member#

Reached through libtmux._internal.dataclasses.SkipDefaultFieldsReprMixin.

Esc

Type to search.

Reference preview Open reference