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

Python API

Python documentation

libtmux.Window.set_hooks

Python
  • Python
  • Ruby Unavailable
  • Lua Unavailable
  • TypeScript Unavailable
  • Rust
  • Go
  • Java Unavailable
  • .NET Unavailable
  • C++ Unavailable
  • Swift Unavailable

View as Markdown

Module
libtmux
Declared in
Window
Package
libtmux
Source
src/libtmux/hooks.py
Other languages
Ruby Lua TypeScript RustGo Java .NET C++ Swift
set_hooks ( self , hook : str , values : HookValues , clear_existing : bool = False , global_ : bool | None = None , scope : OptionScope | _DefaultOptionScope | None = DEFAULT_OPTION_SCOPE ) → Self
method [source]
method [source]
set_hooks

Inherited from libtmux.hooks.HooksMixin

Set multiple indexed hooks at once.

Parameters
  • hook ( str ) – Hook name, e.g. 'session-renamed'

  • values ( HookValues ) – Values to set. Can be: - dict[int, str]: {0: 'cmd1', 1: 'cmd2'} - explicit indices - SparseArray[str]: preserves indices from another hook - list[str]: ['cmd1', 'cmd2'] - sequential indices starting at 0

  • clear_existing ( bool ) – If True, unset all existing hook values first

  • global_ ( bool | None ) – Use global hooks

  • scope ( OptionScope | _DefaultOptionScope | None ) – Scope for the hook

Returns

Self Returns self for method chaining.

In other ports Write a window hook and its indexed commands at once
  • Ruby No source-verified Ruby equivalent is recorded for this operation.
  • Lua No source-verified Lua equivalent is recorded for this operation.
  • TypeScript no equivalent on Window
  • Rust window.Window.set_hooks
  • Go tmux.Window.SetHooks
  • Java no equivalent on Window
  • .NET no equivalent on Window
  • C++ no equivalent on Window
  • Swift no equivalent on Window

Examples

Set hooks with explicit indices:

>>> session.set_hooks('session-renamed', {
... 0: 'display-message "hook 0"',
... 1: 'display-message "hook 1"',
... })
Session($...)
>>> hooks = session.show_hook('session-renamed')
>>> sorted(hooks.keys())
[0, 1]
>>> session.unset_hook('session-renamed')
Session($...)

Set hooks from a list (sequential indices):

>>> session.set_hooks('after-new-window', [
... 'select-pane -t 0',
... 'send-keys "clear" Enter',
... ])
Session($...)
>>> hooks = session.show_hook('after-new-window')
>>> sorted(hooks.keys())
[0, 1]

Replace all existing hooks with clear_existing=True:

>>> session.set_hooks(
... 'session-renamed',
... {0: 'display-message "new"'},
... clear_existing=True,
... )
Session($...)
>>> hooks = session.show_hook('session-renamed')
>>> sorted(hooks.keys())
[0]
>>> session.unset_hook('session-renamed')
Session($...)
>>> session.unset_hook('after-new-window')
Session($...)
use std::collections::BTreeMap;
use libtmux::{IndexedHooks, ReplaceMode, TmuxText};
let guard = libtmux::test::TestServer::new().await?;
let session = guard.server().new_session("hooked").await?;
let window = session.active_window().await?.expect("a window");
let mut entries = BTreeMap::new();
entries.insert(0, TmuxText::from(b"display-message first".to_vec()));
entries.insert(3, TmuxText::from(b"display-message fourth".to_vec()));
window
.set_hooks("pane-died", &IndexedHooks::from(entries), ReplaceMode::Replace)
.await?;
let written = window.hook("pane-died").await?.expect("the hook is set");
assert_eq!(written.len(), 2);
assert!(written.get(1).is_none(), "the gap is kept");
guard.shutdown().await?;

0 declared, 0 inherited

Esc

Type to search.