Panes¶
Contain pseudoterminals (pty(4))
Exist inside Windows
Identified by
%, e.g.%313
- class libtmux.Pane[source]¶
Bases:
Obj,OptionsMixin,HooksMixinPaneinstances can send commands directly to a pane, or traverse between linked tmux objects.Examples
>>> pane Pane(%1 Window(@1 1:..., Session($1 ...)))
>>> pane in window.panes True
>>> pane.window Window(@1 1:..., Session($1 ...))
>>> pane.session Session($1 ...)
The pane can be used as a context manager to ensure proper cleanup:
>>> with window.split() as pane: ... pane.send_keys('echo "Hello"') ... # Do work with the pane ... # Pane will be killed automatically when exiting the context
Notes
Changed in version 0.8: Renamed from
.tmuxto.cmd.References
[pane_manual]- tmux pane. openbsd manpage for TMUX(1).
“Each window displayed by tmux may be split into one or more panes; each pane takes up a certain area of the display and is a separate terminal.”
https://man.openbsd.org/tmux.1#WINDOWS_AND_PANES. Accessed April 1st, 2018.
When not a user (custom) option, scope can be implied.
- cmd(cmd, *args, target=None)[source]¶
Execute tmux subcommand within pane context.
Automatically binds target by adding
-tfor object’s pane ID to the command. Passtargetto keyword arguments to override.Examples
>>> pane.cmd('split-window', '-P').stdout[0] 'libtmux...:...'
From raw output to an enriched Pane object:
>>> Pane.from_pane_id(pane_id=pane.cmd( ... 'split-window', '-P', '-F#{pane_id}').stdout[0], server=pane.server) Pane(%... Window(@... ...:..., Session($1 libtmux_...)))
- resize(adjustment_direction=None, adjustment=None, height=None, width=None, zoom=None, mouse=None, trim_below=None)[source]¶
Resize tmux pane.
- Return type:
- Parameters:
adjustment_direction (ResizeAdjustmentDirection, optional) – direction to adjust,
Up,Down,Left,Right.adjustment (ResizeAdjustmentDirection, optional)
height (int, optional) –
resize-pane -ydimensionswidth (int, optional) –
resize-pane -xdimensionszoom (bool) – expand pane
mouse (bool) – resize via mouse
trim_below (bool) – trim below cursor
- Raises:
- Return type:
Notes
Three types of resizing are available:
Adjustments:
adjustment_directionandadjustment.Manual resizing:
heightand / orwidth.Zoom / Unzoom:
zoom.
- capture_pane(start=None, end=None, *, escape_sequences=False, escape_non_printable=False, join_wrapped=False, preserve_trailing=False, trim_trailing=False)[source]¶
Capture text from pane.
$ tmux capture-paneto pane.$ tmux capture-pane -S -10to pane.$ tmux capture-pane -E 3to pane.$ tmux capture-pane -S - -E -to pane.- Return type:
- Parameters:
start (str | int, optional) – Specify the starting line number. Zero is the first line of the visible pane. Positive numbers are lines in the visible pane. Negative numbers are lines in the history.
-is the start of the history. Default: Noneend (str | int, optional) – Specify the ending line number. Zero is the first line of the visible pane. Positive numbers are lines in the visible pane. Negative numbers are lines in the history.
-is the end of the visible pane. Default: Noneescape_sequences (bool, optional) – Include ANSI escape sequences for text and background attributes (
-eflag). Useful for capturing colored output. Default: Falseescape_non_printable (bool, optional) – Escape non-printable characters as octal
\\xxxformat (-Cflag). Useful for binary-safe capture. Default: Falsejoin_wrapped (bool, optional) – Join wrapped lines and preserve trailing spaces (
-Jflag). Lines that were wrapped by tmux will be joined back together. Default: Falsepreserve_trailing (bool, optional) – Preserve trailing spaces at each line’s end (
-Nflag). Default: Falsetrim_trailing (bool, optional) – Trim trailing positions with no characters (
-Tflag). Only includes characters up to the last used cell. Requires tmux 3.4+. If used with tmux < 3.4, a warning is issued and the flag is ignored. Default: False
- Returns:
Captured pane content.
- Return type:
Examples
>>> pane = window.split(shell='sh') >>> pane.capture_pane() ['$']
>>> pane.send_keys('echo "Hello world"', enter=True)
>>> pane.capture_pane() ['$ echo "Hello world"', 'Hello world', '$']
>>> print(chr(10).join(pane.capture_pane())) $ echo "Hello world" Hello world $
- send_keys(cmd, enter=True, suppress_history=False, literal=False)[source]¶
$ tmux send-keysto the pane.A leading space character is added to cmd to avoid polluting the user’s history.
- Return type:
- Parameters:
cmd (str) – Text or input into pane
enter (bool, optional) – Send enter after sending the input, default True.
suppress_history (bool, optional) –
Prepend a space to command to suppress shell history, default False.
Changed in version 0.14: Default changed from True to False.
literal (bool, optional) – Send keys literally, default False.
Examples
>>> pane = window.split(shell='sh') >>> pane.capture_pane() ['$']
>>> pane.send_keys('echo "Hello world"', enter=True)
>>> pane.capture_pane() ['$ echo "Hello world"', 'Hello world', '$']
>>> print('\n'.join(pane.capture_pane())) $ echo "Hello world" Hello world $
- display_message(cmd, get_text=False)[source]¶
Display message to pane.
Displays a message in target-client status line.
- kill(all_except=None)[source]¶
Kill
Pane.$ tmux kill-pane.Examples
Kill a pane:
>>> pane_1 = pane.split()
>>> pane_1 in window.panes True
>>> pane_1.kill()
>>> pane_1 not in window.panes True
Kill all panes except the current one:
>>> pane.window.resize(height=100, width=100) Window(@1 1...)
>>> one_pane_to_rule_them_all = pane.split()
>>> other_panes = pane.split( ... ), pane.split()
>>> all([p in window.panes for p in other_panes]) True
>>> one_pane_to_rule_them_all.kill(all_except=True)
>>> all([p not in window.panes for p in other_panes]) True
>>> one_pane_to_rule_them_all in window.panes True
- select()[source]¶
Select pane.
- Return type:
Examples
>>> pane = window.active_pane >>> new_pane = window.split() >>> pane.refresh() >>> active_panes = [p for p in window.panes if p.pane_active == '1']
>>> pane in active_panes True >>> new_pane in active_panes False
>>> new_pane.pane_active == '1' False
>>> new_pane.select() Pane(...)
>>> new_pane.pane_active == '1' True
- select_pane()[source]¶
Select pane.
- Return type:
Notes
Deprecated since version 0.30: Deprecated in favor of
select().
- split(target=None, start_directory=None, attach=False, direction=None, full_window_split=None, zoom=None, shell=None, size=None, environment=None)[source]¶
Split window and return
Pane, by default beneath current pane.- Return type:
Pane
- Parameters:
target (optional) – Optional, custom target-pane, used by
Window.split().attach (bool, optional) – make new window the current window after creating it, default True.
start_directory (str or PathLike, optional) – specifies the working directory in which the new window is created.
direction (PaneDirection, optional) – split in direction. If none is specified, assume down.
full_window_split (bool, optional) – split across full window width or height, rather than active pane.
zoom (bool, optional) – expand pane
shell (str, optional) –
execute a command on splitting the window. The pane will close when the command exits.
NOTE: When this command exits the pane will close. This feature is useful for long-running processes where the closing of the window upon completion is desired.
size (int, optional) – Cell/row or percentage to occupy with respect to current window.
environment (dict, optional) – Environmental variables for new pane. Passthrough to
-e.
Examples
>>> (pane.at_left, pane.at_right, ... pane.at_top, pane.at_bottom) (True, True, True, True)
>>> new_pane = pane.split()
>>> (new_pane.at_left, new_pane.at_right, ... new_pane.at_top, new_pane.at_bottom) (True, True, False, True)
>>> right_pane = pane.split(direction=PaneDirection.Right)
>>> (right_pane.at_left, right_pane.at_right, ... right_pane.at_top, right_pane.at_bottom) (False, True, True, False)
>>> left_pane = pane.split(direction=PaneDirection.Left)
>>> (left_pane.at_left, left_pane.at_right, ... left_pane.at_top, left_pane.at_bottom) (True, False, True, False)
>>> top_pane = pane.split(direction=PaneDirection.Above)
>>> (top_pane.at_left, top_pane.at_right, ... top_pane.at_top, top_pane.at_bottom) (False, False, True, False)
>>> pane = session.new_window().active_pane
>>> top_pane = pane.split(direction=PaneDirection.Above, full_window_split=True)
>>> (top_pane.at_left, top_pane.at_right, ... top_pane.at_top, top_pane.at_bottom) (True, True, True, False)
>>> bottom_pane = pane.split( ... direction=PaneDirection.Below, ... full_window_split=True)
>>> (bottom_pane.at_left, bottom_pane.at_right, ... bottom_pane.at_top, bottom_pane.at_bottom) (True, True, False, True)
- enter()[source]¶
Send carriage return to pane.
$ tmux send-keyssend Enter to the pane.- Return type:
- property index: str | None¶
Alias of
Pane.pane_index.>>> pane.index '0'
>>> pane.index == pane.pane_index True
- property height: str | None¶
Alias of
Pane.pane_height.>>> pane.height.isdigit() True
>>> pane.height == pane.pane_height True
- property width: str | None¶
Alias of
Pane.pane_width.>>> pane.width.isdigit() True
>>> pane.width == pane.pane_width True
- property at_top: bool¶
Typed, converted wrapper around
Pane.pane_at_top.>>> pane.pane_at_top '1'
>>> pane.at_top True
- property at_bottom: bool¶
Typed, converted wrapper around
Pane.pane_at_bottom.>>> pane.pane_at_bottom '1'
>>> pane.at_bottom True
- property at_left: bool¶
Typed, converted wrapper around
Pane.pane_at_left.>>> pane.pane_at_left '1'
>>> pane.at_left True
- property at_right: bool¶
Typed, converted wrapper around
Pane.pane_at_right.>>> pane.pane_at_right '1'
>>> pane.at_right True
- split_window(target=None, attach=False, start_directory=None, vertical=True, shell=None, size=None, percent=None, environment=None)[source]¶
Split window at pane and return newly created
Pane.- Return type:
Pane
- Parameters:
attach (bool, optional) – Attach / select pane after creation.
start_directory (str or PathLike, optional) – specifies the working directory in which the new pane is created.
vertical (bool, optional) – split vertically
percent (int, optional) – percentage to occupy with respect to current pane
environment (dict, optional) – Environmental variables for new pane. Passthrough to
-e.shell (str | None)
Notes
Deprecated since version 0.33: Deprecated in favor of
split().
- __init__(server, active_window_index=None, alternate_saved_x=None, alternate_saved_y=None, buffer_name=None, buffer_sample=None, buffer_size=None, client_cell_height=None, client_cell_width=None, client_discarded=None, client_flags=None, client_height=None, client_key_table=None, client_name=None, client_pid=None, client_termname=None, client_tty=None, client_uid=None, client_user=None, client_width=None, client_written=None, command_list_alias=None, command_list_name=None, command_list_usage=None, config_files=None, copy_cursor_line=None, copy_cursor_word=None, copy_cursor_x=None, copy_cursor_y=None, current_file=None, cursor_character=None, cursor_flag=None, cursor_x=None, cursor_y=None, history_bytes=None, history_limit=None, history_size=None, insert_flag=None, keypad_cursor_flag=None, keypad_flag=None, last_window_index=None, line=None, mouse_all_flag=None, mouse_any_flag=None, mouse_button_flag=None, mouse_sgr_flag=None, mouse_standard_flag=None, next_session_id=None, origin_flag=None, pane_active=None, pane_at_bottom=None, pane_at_left=None, pane_at_right=None, pane_at_top=None, pane_bg=None, pane_bottom=None, pane_current_command=None, pane_current_path=None, pane_dead_signal=None, pane_dead_status=None, pane_dead_time=None, pane_fg=None, pane_height=None, pane_id=None, pane_index=None, pane_left=None, pane_pid=None, pane_right=None, pane_search_string=None, pane_start_command=None, pane_start_path=None, pane_tabs=None, pane_top=None, pane_tty=None, pane_width=None, pid=None, scroll_position=None, scroll_region_lower=None, scroll_region_upper=None, search_match=None, selection_end_x=None, selection_end_y=None, selection_start_x=None, selection_start_y=None, session_activity=None, session_alerts=None, session_attached=None, session_attached_list=None, session_created=None, session_group=None, session_group_attached=None, session_group_list=None, session_group_size=None, session_id=None, session_last_attached=None, session_name=None, session_path=None, session_stack=None, session_windows=None, socket_path=None, start_time=None, uid=None, user=None, version=None, window_active=None, window_active_clients=None, window_active_sessions=None, window_activity=None, window_cell_height=None, window_cell_width=None, window_height=None, window_id=None, window_index=None, window_layout=None, window_linked=None, window_linked_sessions=None, window_linked_sessions_list=None, window_marked_flag=None, window_name=None, window_offset_x=None, window_offset_y=None, window_panes=None, window_raw_flags=None, window_stack_index=None, window_width=None, wrap_flag=None, default_option_scope=OptionScope.Pane, default_hook_scope=OptionScope.Pane)[source]¶
When not a user (custom) option, scope can be implied.
- Parameters:
server (Server)
active_window_index (str | None)
alternate_saved_x (str | None)
alternate_saved_y (str | None)
buffer_name (str | None)
buffer_sample (str | None)
buffer_size (str | None)
client_cell_height (str | None)
client_cell_width (str | None)
client_discarded (str | None)
client_flags (str | None)
client_height (str | None)
client_key_table (str | None)
client_name (str | None)
client_pid (str | None)
client_termname (str | None)
client_tty (str | None)
client_uid (str | None)
client_user (str | None)
client_width (str | None)
client_written (str | None)
command_list_alias (str | None)
command_list_name (str | None)
command_list_usage (str | None)
config_files (str | None)
copy_cursor_line (str | None)
copy_cursor_word (str | None)
copy_cursor_x (str | None)
copy_cursor_y (str | None)
current_file (str | None)
cursor_character (str | None)
cursor_flag (str | None)
cursor_x (str | None)
cursor_y (str | None)
history_bytes (str | None)
history_limit (str | None)
history_size (str | None)
insert_flag (str | None)
keypad_cursor_flag (str | None)
keypad_flag (str | None)
last_window_index (str | None)
line (str | None)
mouse_all_flag (str | None)
mouse_any_flag (str | None)
mouse_button_flag (str | None)
mouse_sgr_flag (str | None)
mouse_standard_flag (str | None)
next_session_id (str | None)
origin_flag (str | None)
pane_active (str | None)
pane_at_bottom (str | None)
pane_at_left (str | None)
pane_at_right (str | None)
pane_at_top (str | None)
pane_bg (str | None)
pane_bottom (str | None)
pane_current_command (str | None)
pane_current_path (str | None)
pane_dead_signal (str | None)
pane_dead_status (str | None)
pane_dead_time (str | None)
pane_fg (str | None)
pane_height (str | None)
pane_id (str | None)
pane_index (str | None)
pane_left (str | None)
pane_pid (str | None)
pane_right (str | None)
pane_search_string (str | None)
pane_start_command (str | None)
pane_start_path (str | None)
pane_tabs (str | None)
pane_top (str | None)
pane_tty (str | None)
pane_width (str | None)
pid (str | None)
scroll_position (str | None)
scroll_region_lower (str | None)
scroll_region_upper (str | None)
search_match (str | None)
selection_end_x (str | None)
selection_end_y (str | None)
selection_start_x (str | None)
selection_start_y (str | None)
session_activity (str | None)
session_alerts (str | None)
session_attached (str | None)
session_attached_list (str | None)
session_created (str | None)
session_group (str | None)
session_group_attached (str | None)
session_group_list (str | None)
session_group_size (str | None)
session_id (str | None)
session_last_attached (str | None)
session_name (str | None)
session_path (str | None)
session_stack (str | None)
session_windows (str | None)
socket_path (str | None)
start_time (str | None)
uid (str | None)
user (str | None)
version (str | None)
window_active (str | None)
window_active_clients (str | None)
window_active_sessions (str | None)
window_activity (str | None)
window_cell_height (str | None)
window_cell_width (str | None)
window_height (str | None)
window_id (str | None)
window_index (str | None)
window_layout (str | None)
window_linked (str | None)
window_linked_sessions (str | None)
window_linked_sessions_list (str | None)
window_marked_flag (str | None)
window_name (str | None)
window_offset_x (str | None)
window_offset_y (str | None)
window_panes (str | None)
window_raw_flags (str | None)
window_stack_index (str | None)
window_width (str | None)
wrap_flag (str | None)
default_option_scope (OptionScope | None)
default_hook_scope (OptionScope | None)
- Return type:
None
- _show_hook(hook, global_=False, scope=<libtmux.constants._DefaultOptionScope object>)[source]¶
Return value for the hook.
- Return type:
- Parameters:
hook (str)
global_ (bool)
scope (OptionScope | _DefaultOptionScope | None)
- Raises:
- _show_option(option, global_=False, g=False, scope=<libtmux.constants._DefaultOptionScope object>, ignore_errors=None, include_hooks=None, include_inherited=None)[source]¶
Return option value for the target.
todo: test and return True/False for on/off string
- Return type:
- Parameters:
- Raises:
Examples
>>> import typing as t >>> from libtmux.common import tmux_cmd >>> from libtmux.constants import OptionScope
>>> class MyServer(OptionsMixin): ... socket_name = server.socket_name ... def cmd(self, cmd: str, *args: object): ... cmd_args: t.List[t.Union[str, int]] = [cmd] ... if self.socket_name: ... cmd_args.insert(0, f"-L{self.socket_name}") ... cmd_args.insert(0, "-f/dev/null") ... return tmux_cmd(*cmd_args, *args) ... ... default_option_scope = OptionScope.Server
>>> MyServer().cmd('new-session', '-d') <libtmux.common.tmux_cmd object at ...>
>>> MyServer()._show_option('exit-unattached', global_=True) False
- _show_option_raw(option, global_=False, g=False, scope=<libtmux.constants._DefaultOptionScope object>, ignore_errors=None, include_hooks=None, include_inherited=None)[source]¶
Return raw option output for target.
- Return type:
tmux_cmd
- Parameters:
- Raises:
Examples
>>> import typing as t >>> from libtmux.common import tmux_cmd >>> from libtmux.constants import OptionScope
>>> class MyServer(OptionsMixin): ... socket_name = server.socket_name ... def cmd(self, cmd: str, *args: object): ... cmd_args: t.List[t.Union[str, int]] = [cmd] ... if self.socket_name: ... cmd_args.insert(0, f"-L{self.socket_name}") ... cmd_args.insert(0, "-f/dev/null") ... return tmux_cmd(*cmd_args, *args) ... ... default_option_scope = OptionScope.Server
>>> MyServer().cmd('new-session', '-d') <libtmux.common.tmux_cmd object at ...>
>>> MyServer()._show_option_raw('exit-unattached', global_=True) <libtmux.common.tmux_cmd object at ...>
>>> MyServer()._show_option_raw('exit-unattached', global_=True).stdout ['exit-unattached off']
>>> isinstance(MyServer()._show_option_raw('exit-unattached', global_=True).stdout, list) True
>>> isinstance(MyServer()._show_option_raw('exit-unattached', global_=True).stdout[0], str) True
- _show_options(g=False, global_=False, scope=<libtmux.constants._DefaultOptionScope object>, include_hooks=None, include_inherited=None)[source]¶
Return a dict of options for the target.
- Return type:
dict[str,str|int|list[str|int] |dict[str,list[str|int]] |SparseArray[str|int] |None]- Parameters:
g (bool, optional) –
Deprecated since version 0.50.0: Use
global_instead.global_ (bool | None)
scope (OptionScope | _DefaultOptionScope | None)
include_hooks (bool | None)
include_inherited (bool | None)
Examples
>>> import typing as t >>> from libtmux.common import tmux_cmd >>> from libtmux.constants import OptionScope
>>> class MyServer(OptionsMixin): ... socket_name = server.socket_name ... def cmd(self, cmd: str, *args: object): ... cmd_args: t.List[t.Union[str, int]] = [cmd] ... if self.socket_name: ... cmd_args.insert(0, f"-L{self.socket_name}") ... cmd_args.insert(0, "-f/dev/null") ... return tmux_cmd(*cmd_args, *args) ... ... default_option_scope = OptionScope.Server
>>> MyServer()._show_options() {...}
- _show_options_dict(g=False, global_=False, scope=<libtmux.constants._DefaultOptionScope object>, include_hooks=None, include_inherited=None)[source]¶
Return dict of options for the target.
- Return type:
- Parameters:
g (bool, optional) –
Deprecated since version 0.50.0: Use
global_instead.global_ (bool | None)
scope (OptionScope | _DefaultOptionScope | None)
include_hooks (bool | None)
include_inherited (bool | None)
Examples
>>> import typing as t >>> from libtmux.common import tmux_cmd >>> from libtmux.constants import OptionScope
>>> class MyServer(OptionsMixin): ... socket_name = server.socket_name ... def cmd(self, cmd: str, *args: object): ... cmd_args: t.List[t.Union[str, int]] = [cmd] ... if self.socket_name: ... cmd_args.insert(0, f"-L{self.socket_name}") ... cmd_args.insert(0, "-f/dev/null") ... return tmux_cmd(*cmd_args, *args) ... ... default_option_scope = OptionScope.Server
>>> MyServer()._show_options_dict() {...}
>>> isinstance(MyServer()._show_options_dict(), dict) True
- _show_options_raw(g=False, global_=False, scope=<libtmux.constants._DefaultOptionScope object>, include_hooks=None, include_inherited=None)[source]¶
Return a dict of options for the target.
- Return type:
tmux_cmd
- Parameters:
g (bool, optional) –
Deprecated since version 0.50.0: Use
global_instead.global_ (bool | None)
scope (OptionScope | _DefaultOptionScope | None)
include_hooks (bool | None)
include_inherited (bool | None)
Examples
>>> import typing as t >>> from libtmux.common import tmux_cmd >>> from libtmux.constants import OptionScope
>>> class MyServer(OptionsMixin): ... socket_name = server.socket_name ... def cmd(self, cmd: str, *args: object): ... cmd_args: t.List[t.Union[str, int]] = [cmd] ... if self.socket_name: ... cmd_args.insert(0, f"-L{self.socket_name}") ... cmd_args.insert(0, "-f/dev/null") ... return tmux_cmd(*cmd_args, *args) ... ... default_option_scope = OptionScope.Server
>>> MyServer()._show_options_raw() <libtmux.common.tmux_cmd object at ...>
>>> MyServer()._show_options_raw().stdout [...]
- get(key, default=None)[source]¶
Return key-based lookup. Deprecated by attributes.
Deprecated since version 0.17: Deprecated by attribute lookup, e.g.
pane['window_name']is now accessed viapane.window_name.
- run_hook(hook, global_=None, scope=<libtmux.constants._DefaultOptionScope object>)[source]¶
Run a hook immediately. Useful for testing.
- Return type:
Self
- Parameters:
hook (str)
global_ (bool | None)
scope (OptionScope | _DefaultOptionScope | None)
- set_hook(hook, value, unset=None, run=None, append=None, g=None, global_=None, scope=<libtmux.constants._DefaultOptionScope object>)[source]¶
Set hook for tmux target.
Wraps
$ tmux set-hook <hook> <value>.- Return type:
Self
- Parameters:
- Raises:
- set_hooks(hook, values, *, clear_existing=False, global_=None, scope=<libtmux.constants._DefaultOptionScope object>)[source]¶
Set multiple indexed hooks at once.
- Return type:
Self
- 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 | None) – Scope for the hook
global_ (bool | None)
- Returns:
Returns self for method chaining.
- Return type:
Self
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($...)
- set_option(option, value, _format=None, prevent_overwrite=None, ignore_errors=None, suppress_warnings=None, append=None, g=None, global_=None, scope=<libtmux.constants._DefaultOptionScope object>)[source]¶
Set option for tmux target.
Wraps
$ tmux set-option <option> <value>.- Return type:
Self
- Parameters:
option (str) – option to set, e.g. ‘aggressive-resize’
value (str) – option value. True/False will turn in ‘on’ and ‘off’, also accepts string of ‘on’ or ‘off’ directly.
deprecated: (..) – 0.28: Deprecated by
gfor global, useglobal_instead._format (bool | None)
prevent_overwrite (bool | None)
ignore_errors (bool | None)
suppress_warnings (bool | None)
append (bool | None)
g (bool | None)
global_ (bool | None)
scope (OptionScope | _DefaultOptionScope | None)
- Raises:
Examples
>>> import typing as t >>> from libtmux.common import tmux_cmd >>> from libtmux.constants import OptionScope >>> from libtmux._internal.sparse_array import SparseArray
>>> class MyServer(OptionsMixin): ... socket_name = server.socket_name ... def cmd(self, cmd: str, *args: object): ... cmd_args: t.List[t.Union[str, int]] = [cmd] ... if self.socket_name: ... cmd_args.insert(0, f"-L{self.socket_name}") ... cmd_args.insert(0, "-f/dev/null") ... return tmux_cmd(*cmd_args, *args) ... ... default_option_scope = OptionScope.Server
>>> MyServer().set_option('escape-time', 1250) <libtmux.options.MyServer object at ...>
>>> MyServer()._show_option('escape-time') 1250
>>> MyServer().set_option('escape-time', 495) <libtmux.options.MyServer object at ...>
>>> MyServer()._show_option('escape-time') 495
- show_hook(hook, global_=False, scope=<libtmux.constants._DefaultOptionScope object>)[source]¶
Return value for a hook.
For array hooks (e.g.,
session-renamed), returns aSparseArraywith hook values at their original indices. Use.keys()for indices and.values()for values.- Return type:
str|int|SparseArray[str] |None- Parameters:
hook (str) – Hook name to query
global_ (bool)
scope (OptionScope | _DefaultOptionScope | None)
- Returns:
Hook value. For array hooks, returns SparseArray.
- Return type:
str | int | SparseArray[str] | None
- Raises:
Examples
>>> session.set_hook('session-renamed[0]', 'display-message "test"') Session($...)
>>> hooks = session.show_hook('session-renamed') >>> isinstance(hooks, SparseArray) True
>>> sorted(hooks.keys()) [0]
>>> session.unset_hook('session-renamed') Session($...)
- show_hooks(global_=False, scope=<libtmux.constants._DefaultOptionScope object>)[source]¶
Return a dict of hooks for the target.
- Return type:
- Parameters:
global (bool, optional) – Pass
-gflag for global hooks, default False.scope (OptionScope | _DefaultOptionScope | None, optional) – Hook scope (Server/Session/Window/Pane), defaults to object’s scope.
global_ (bool | None)
- Returns:
Dictionary mapping hook names to their values.
- Return type:
HookDict
Examples
>>> session.set_hook('session-renamed[0]', 'display-message "test"') Session($...)
>>> hooks = session.show_hooks() >>> isinstance(hooks, dict) True
>>> 'session-renamed[0]' in hooks True
>>> session.unset_hook('session-renamed') Session($...)
- show_option(option, global_=False, g=False, scope=<libtmux.constants._DefaultOptionScope object>, ignore_errors=None, include_hooks=None, include_inherited=None)[source]¶
Return option value for the target.
- Return type:
- Parameters:
- Raises:
Examples
>>> import typing as t >>> from libtmux.common import tmux_cmd >>> from libtmux.constants import OptionScope
>>> class MyServer(OptionsMixin): ... socket_name = server.socket_name ... def cmd(self, cmd: str, *args: object): ... cmd_args: t.List[t.Union[str, int]] = [cmd] ... if self.socket_name: ... cmd_args.insert(0, f"-L{self.socket_name}") ... cmd_args.insert(0, "-f/dev/null") ... return tmux_cmd(*cmd_args, *args) ... ... default_option_scope = OptionScope.Server
>>> MyServer().cmd('new-session', '-d') <libtmux.common.tmux_cmd object at ...>
>>> MyServer().show_option('exit-unattached', global_=True) False
- show_options(global_=False, scope=<libtmux.constants._DefaultOptionScope object>, include_hooks=None, include_inherited=None)[source]¶
Return all options for the target.
- Return type:
dict[str,str|int|list[str|int] |dict[str,list[str|int]] |SparseArray[str|int] |None]- Parameters:
global (bool, optional) – Pass
-gflag for global options, default False.scope (OptionScope | _DefaultOptionScope | None, optional) – Option scope (Server/Session/Window/Pane), defaults to object’s scope.
include_hooks (bool, optional) – Include hook options (
-Hflag).include_inherited (bool, optional) – Include inherited options (
-Aflag).global_ (bool)
- Returns:
Dictionary with all options, arrays exploded and values converted.
- Return type:
ExplodedComplexUntypedOptionsDict
- Raises:
Examples
>>> options = server.show_options() >>> isinstance(options, dict) True
>>> 'buffer-limit' in options True
- unset_hook(hook, global_=None, scope=<libtmux.constants._DefaultOptionScope object>)[source]¶
Unset hook for tmux target.
Wraps
$ tmux set-hook -u <hook>/$ tmux set-hook -U <hook>- Return type:
Self
- Parameters:
hook (str) – hook to unset, e.g. ‘after-show-environment’
global_ (bool | None)
scope (OptionScope | _DefaultOptionScope | None)
- Raises:
- unset_option(option, unset_panes=None, global_=None, ignore_errors=None, scope=<libtmux.constants._DefaultOptionScope object>)[source]¶
Unset option for tmux target.
Wraps
$ tmux set-option -u <option>/$ tmux set-option -U <option>- Return type:
Self
- Parameters:
option (str) – option to unset, e.g. ‘aggressive-resize’
unset_panes (bool | None)
global_ (bool | None)
ignore_errors (bool | None)
scope (OptionScope | _DefaultOptionScope | None)
- Raises:
Examples
>>> import typing as t >>> from libtmux.common import tmux_cmd >>> from libtmux.constants import OptionScope
>>> class MyServer(OptionsMixin): ... socket_name = server.socket_name ... def cmd(self, cmd: str, *args: object): ... cmd_args: t.List[t.Union[str, int]] = [cmd] ... if self.socket_name: ... cmd_args.insert(0, f"-L{self.socket_name}") ... cmd_args.insert(0, "-f/dev/null") ... return tmux_cmd(*cmd_args, *args) ... ... default_option_scope = OptionScope.Server
>>> MyServer().set_option('escape-time', 1250) <libtmux.options.MyServer object at ...>
>>> MyServer()._show_option('escape-time') 1250
>>> MyServer().unset_option('escape-time') <libtmux.options.MyServer object at ...>
>>> isinstance(MyServer()._show_option('escape-time'), int) True
- resize_pane(adjustment_direction=None, adjustment=None, height=None, width=None, zoom=None, mouse=None, trim_below=None)[source]¶
Resize pane, deprecated by
Pane.resize().Deprecated since version 0.28: Deprecated by
Pane.resize().