Options and hooks
Use options to change tmux behavior, such as automatic-rename or the
status-line format. Use hooks to run commands on events such as
session-renamed or after-split-window. Choose the scope supported by the
option or hook.
Reading and writing options¶
Read, set, or unset an option at its supported scope. Distinguish a local override from the effective value inherited from a parent scope.
Read all (this scope): server.options(.pane(pane))
Read effective/inherited: server.option(name, scope: .pane(pane)) reads
presence from the listing, then the value with -v
Set: server.setOption(name, to: value, scope: .pane(pane))
Unset: server.unsetOption(name, scope: .pane(pane))
Examples¶
After a successful write completes, read the option to obtain its updated value. The following examples set, read, and unset an option:
try await server.setOption("automatic-rename", to: "off", scope: .pane(pane))try await server.options(.pane(pane))try await server.unsetOption("automatic-rename", scope: .pane(pane))Hooks¶
Set: server.setHook(name, to: command, at: index, in: scope)
Unset: server.unsetHook(name, in: scope)
List: server.hooks(scope)
Run now, without the event: server.runHook(name, in: scope)
Examples¶
tmux stores hook commands in indexed arrays, such as after-new-window[0].
The at: parameter selects the array index.
Set and list a session hook. The next section explains window and pane scope limitations:
try await server.setHook("session-renamed", to: "display-message 'renamed'", in: .session(session.id.rawValue))try await server.hooks(.session(session.id.rawValue))Supported hook scopes¶
tmux stores hooks globally or per session. Accepted set-hook -w or -p flags
do not imply a separate window or pane hook table, and show-hooks does not
provide a corresponding listing. Check the event’s supported scope if a hook is
accepted but never fires.
HookScope restricts registration to .global and .session.
Options have window and pane tables of their own. The hook-scope limitation does not apply to ordinary options.
tmux version compatibility¶
Check the library’s supported tmux versions before using a version-specific option or hook.
tmux manual and source
The tmux manual defines option scopes and inherited reads. Unsetting a local value restores inheritance. Hook programs run in tmux when their event occurs; see the hook implementation.