Panes¶
Contain pseudoterminals (pty(4))
Exist inside Windows
Identified by
%, e.g.%313
Bases:
Obj,OptionsMixin,HooksMixinPaneinstances can send commands directly to a pane, or traverse between linked tmux objects.-
attributeattribute
Scope
OptionsMixinfalls back to when an option call leavesscopeunset.OptionScope.Panesendsset-optionandshow-optionswith tmux’s-pflag;Nonesends no scope flag, which tmux resolves as session scope.
-
attributeattribute
Scope
HooksMixinfalls back to when a hook call leavesscopeunset.OptionScope.Panesendsset-hookandshow-hookswith tmux’s-pflag;Nonesends no scope flag, which tmux resolves as session scope.
Server the pane was queried from, and the connection every command and refresh runs over.
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.
Refresh pane attributes from tmux.
Scoped to this pane’s own window (
list-panes -t %ID), so tmux – not libtmux – decides which session the pane belongs to. SeePane.from_pane_id().- Raises:
ValueError– Whenpane_idis unset. Surfaces a clear error underpython -O, where anassertwould be stripped.TmuxObjectDoesNotExist– When the pane no longer exists.LibTmuxException– When tmux itself is unreachable.
- Return type:
Examples
>>> pane.refresh() >>> pane.pane_id '%1'
Create Pane from existing pane_id.
tmux’s
cmd_findroutes a-ttarget by sigil, so a%-id handed tolist-panesresolves to that pane’s window and lists it. Every row comes back stamped with the session tmux considers canonical for that window – the most recently active one – which is the same sessiondisplay-message -t %ID '#{session_id}'reports. A window linked into several sessions therefore gets one authoritative answer instead of “whichever session sorted last”.- Parameters:
- Return type:
- Raises:
TmuxObjectDoesNotExist– When no such pane exists on a reachable server.LibTmuxException– When tmux itself is unreachable.
Examples
>>> Pane.from_pane_id(server=pane.server, pane_id=pane.pane_id) Pane(%1 Window(@1 1:..., Session($1 ...)))
Return the pane this process is running inside of.
Reads
$TMUXfor the server’s socket and$TMUX_PANEfor the pane id, then asks tmux for the rest. The stale session id inside$TMUXis never consulted, so the answer stays correct after the pane’s window has been moved or linked elsewhere.- Parameters:
env (
typing.Mapping, optional) – Environment to read. Defaults toos.environ, which is what a process running inside a pane wants; pass an explicit mapping to resolve on behalf of another pane.- Return type:
- Raises:
NotInsideTmux– When$TMUXor$TMUX_PANEis unset or malformed.TmuxObjectDoesNotExist– When the pane named by$TMUX_PANEis gone.LibTmuxException– When the server named by$TMUXis unreachable.
Examples
>>> Pane.from_env(env) Pane(%1 Window(@1 1:..., Session($1 ...)))
>>> Pane.from_env(env).pane_id == pane.pane_id True
Outside a pane there is nothing to resolve:
>>> from libtmux import exc >>> try: ... Pane.from_env({}) ... except exc.NotInsideTmux as e: ... print(e) Not inside a tmux pane: $TMUX is unset or empty
Added in version 0.62.
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 tmux pane.
- 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 panemouse (
bool) – resize via mousetrim_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: Literal['-'] | int | None = None, end: Literal['-'] | int | None = None, *, escape_sequences: bool = False, escape_non_printable: bool = False, join_wrapped: bool = False, preserve_trailing: bool = False, trim_trailing: bool = False, alternate_screen: bool = False, quiet: bool = False, mode_screen: bool = False, pending: bool = False, hyperlinks: bool = False, line_numbers: bool = False, line_flags: bool = False, to_buffer: str) → None¶method[source]method[source]capture_pane(start: Literal['-'] | int | None = None, end: Literal['-'] | int | None = None, *, escape_sequences: bool = False, escape_non_printable: bool = False, join_wrapped: bool = False, preserve_trailing: bool = False, trim_trailing: bool = False, alternate_screen: bool = False, quiet: bool = False, mode_screen: bool = False, pending: bool = False, hyperlinks: bool = False, line_numbers: bool = False, line_flags: bool = False, to_buffer: str) → None¶
-
capture_pane(start: Literal['-'] | int | None = None, end: Literal['-'] | int | None = None, *, escape_sequences: bool = False, escape_non_printable: bool = False, join_wrapped: bool = False, preserve_trailing: bool = False, trim_trailing: bool = False, alternate_screen: bool = False, quiet: bool = False, mode_screen: bool = False, pending: bool = False, hyperlinks: bool = False, line_numbers: bool = False, line_flags: bool = False, to_buffer: None = None) → list[str]methodmethodcapture_pane(start: Literal['-'] | int | None = None, end: Literal['-'] | int | None = None, *, escape_sequences: bool = False, escape_non_printable: bool = False, join_wrapped: bool = False, preserve_trailing: bool = False, trim_trailing: bool = False, alternate_screen: bool = False, quiet: bool = False, mode_screen: bool = False, pending: bool = False, hyperlinks: bool = False, line_numbers: bool = False, line_flags: bool = False, to_buffer: None = None) → list[str]
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.- 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: Falsealternate_screen (
bool,optional) –Capture from the alternate screen (
-aflag). Default: FalseAdded in version 0.56.
quiet (
bool,optional) –Suppress errors silently (
-qflag). Default: FalseAdded in version 0.56.
mode_screen (
bool,optional) –Capture from the mode screen (e.g. copy mode) instead of the pane (
-Mflag). Requires tmux 3.6+. Default: FalseAdded in version 0.56.
pending (
bool,optional) –Capture pending output — the bytes tmux has read from the pane but not yet committed to the terminal (
-Pflag). These are bytes that begin an incomplete escape sequence and are still pending the parser’s ground state (tmux’sinput_pending()/since_groundbuffer), distinct from the default capture (the pane’s screen history). Useful for diagnosing programs whose output stalls mid-sequence. Default: FalseAdded in version 0.57.
hyperlinks (
bool,optional) – Capture only hyperlink targets in the selected lines (-Hflag). Requires tmux 3.7+. If used with tmux < 3.7, a warning is issued and the flag is ignored. Default: Falseline_numbers (
bool,optional) – Prefix each captured line with its line number (-Lflag). Requires tmux 3.7+. If used with tmux < 3.7, a warning is issued and the flag is ignored. Default: Falseline_flags (
bool,optional) – Prefix each captured line with its flags, e.g.Hfor a line with a hyperlink (-Fflag). Requires tmux 3.7+. If used with tmux < 3.7, a warning is issued and the flag is ignored. Default: Falseto_buffer (
str,optional) –Write the capture into the named tmux buffer (
-bflag) instead of returning it. When set,-pis omitted and the wrapper returnsNone.Added in version 0.56.
- Returns:
Captured pane content, or
Nonewhen to_buffer is set.- 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 $
$ tmux send-keysto the pane.A leading space character is added to cmd to avoid polluting the user’s history.
When
cmdis omitted (None), the wrapper emits a flag-only invocation — useful withreset=Trueorrepeat=Nto invoke tmux’s deliberatecount == 0branch incmd-send-keys.cthat runs the flag effect without sending any keys. In flag-only mode,enteris forcedFalse(no keys → no Enter).- Parameters:
Text or input into pane.
Nonefor flag-only invocation (requiresreset,repeat, orcopy_mode_cmdto be set).Changed in version 0.57: Now optional.
Nonetriggers tmux’s flag-only path.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.reset (
bool,optional) –Reset terminal state before sending keys (
-Rflag).Added in version 0.56.
copy_mode_cmd (
str,optional) –Send a command to copy mode instead of keys (
-Xflag). When set, cmd is ignored.Added in version 0.56.
repeat (
int,optional) –Repeat count for the key (
-Nflag).Added in version 0.56.
expand_formats (
bool,optional) –Expand tmux format strings in keys (
-Fflag).Added in version 0.56.
hex_keys (
bool,optional) –Send keys as hex values (
-Hflag).Added in version 0.56.
target_client (
str,optional) –Specify a target client (
-cflag). Requires tmux 3.4+.Added in version 0.56.
key_name (
bool,optional) –Handle keys as key names (
-Kflag). Requires tmux 3.4+.Added in version 0.56.
- Raises:
ValueError– IfcmdisNoneand no flag-only path is selected (reset,repeat, orcopy_mode_cmd).- 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('\n'.join(pane.capture_pane())) $ echo "Hello world" Hello world $
Flag-only invocation — reset terminal state without sending any keys:
>>> pane.send_keys(reset=True)
-
display_message(cmd: str, get_text: Literal[True], *, format_string: str | None = None, all_formats: bool | None = None, verbose: bool | None = None, no_expand: bool | None = None, target_client: str | None = None, delay: int | None = None, notify: bool | None = None, update_pane: bool | None = None) → list[str]¶method[source]method[source]display_message(cmd: str, get_text: Literal[True], *, format_string: str | None = None, all_formats: bool | None = None, verbose: bool | None = None, no_expand: bool | None = None, target_client: str | None = None, delay: int | None = None, notify: bool | None = None, update_pane: bool | None = None) → list[str]¶
-
display_message(cmd: str, get_text: Literal[False] = False, *, format_string: str | None = None, all_formats: bool | None = None, verbose: bool | None = None, no_expand: bool | None = None, target_client: str | None = None, delay: int | None = None, notify: bool | None = None, update_pane: bool | None = None) → Nonemethodmethoddisplay_message(cmd: str, get_text: Literal[False] = False, *, format_string: str | None = None, all_formats: bool | None = None, verbose: bool | None = None, no_expand: bool | None = None, target_client: str | None = None, delay: int | None = None, notify: bool | None = None, update_pane: bool | None = None) → None
Display message to pane.
Displays a message in target-client status line. The
get_text=Falsepath renders in the status line and is not programmatically verifiable; onlyget_text=Truereturns output.- Parameters:
cmd (
str) – Special parameters to request from pane.get_text (
bool,optional) – Returns only text without displaying a message in target-client status line.format_string (
str,optional) –Format string for output (
-Fflag).Added in version 0.56.
all_formats (
bool,optional) –List all format variables (
-aflag).Added in version 0.56.
verbose (
bool,optional) –Show format variable types (
-vflag).Added in version 0.56.
no_expand (
bool,optional) –Suppress format expansion; output is returned as a literal string (
-lflag). Requires tmux 3.4+.Added in version 0.56.
target_client (
str,optional) –Target client (
-cflag).Added in version 0.56.
delay (
int,optional) –Display time in milliseconds (
-dflag).Added in version 0.56.
notify (
bool,optional) –Do not wait for input (
-Nflag).Added in version 0.56.
update_pane (
bool,optional) –Allow the pane to keep updating while the message is displayed (
-Cflag). By default tmux freezes the pane while a status message is shown. Requires tmux 3.6+ (introduced upstream by commit80eb460f).Added in version 0.56.
- Returns:
Message output if get_text is True, otherwise None.
- Return type:
Notes
Stderr from tmux is reported via
warnings.warn(), not raised. Callers that want to escalate to an exception can wrap the call inwarnings.catch_warnings()withfilterwarnings("error").Changed in version 0.57: Reports stderr via
warnings.warn()instead of raising.
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 pane.
- Parameters:
direction (
ResizeAdjustmentDirection,optional) –Select the pane in the given direction (
-U,-D,-L,-R).Added in version 0.56.
last (
bool,optional) –Select the last (previously selected) pane (
-lflag).Added in version 0.56.
keep_zoom (
bool,optional) –Keep the window zoomed if it was zoomed (
-Zflag).Added in version 0.56.
mark (
bool,optional) –Set the marked pane (
-mflag).Added in version 0.56.
clear_mark (
bool,optional) –Clear the marked pane (
-Mflag).Added in version 0.56.
disable_input (
bool,optional) –Disable input to the pane (
-dflag).Added in version 0.56.
enable_input (
bool,optional) –Enable input to the pane (
-eflag).Added in version 0.56.
- Returns:
Self, for method chaining.
- 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
- Return type:
Split window and return
Pane, by default beneath current pane.- Parameters:
target (
optional) – Optional, custom target-pane, used byWindow.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 paneshell (
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 count to occupy with respect to current window.percentage (
int,optional) –Percentage (0-100) of the window to occupy (
-pflag). Mutually exclusive with size.Added in version 0.56.
environment (
dict,optional) – Environmental variables for new pane. Passthrough to-e.empty (
bool,optional) – Create an empty pane with no command (-Eflag) instead of spawning the default shell. Requires tmux 3.7+. If used with tmux < 3.7, a warning is issued and the flag is ignored.style (
str,optional) – Style for the new pane (-s). Requires tmux 3.7+.active_border_style (
str,optional) – Active-pane border style (-S). Requires tmux 3.7+.inactive_border_style (
str,optional) – Inactive-pane border style (-R). Requires tmux 3.7+.message (
str,optional) – Keep the pane open (until a key is pressed) after exit, showing thisremain-on-exit-formatmessage (-m). Requires tmux 3.7+.keep (
bool,optional) – Keep the pane open until a key is pressed after exit (-k). Requires tmux 3.7+. These 3.7 flags warn and are ignored below 3.7.
- Return type:
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)
Create a floating
Panevia$ tmux new-pane(tmux 3.7+).Use
split()for a tiled pane. Floating panes sit above the tiled layout like a popup, but unlike a popup they are not modal and behave like normal panes. The returned pane haspane_floating_flag == "1".- Parameters:
target (
int or str, optional) – Custom target-pane, used byWindow.new_pane().start_directory (
str or PathLike, optional) – Working directory for the new pane (-cflag).attach (
bool,optional) – Make the new pane the active pane, default False (-dwhen not attaching).shell (
str,optional) – Command to run in the pane. The pane closes when it exits.environment (
dict,optional) – Environment variables for the new pane (-eflag).width (
int,optional) – Width of the floating pane in cells (-xflag).height (
int,optional) – Height of the floating pane in cells (-yflag).x (
int,optional) – X position of the floating pane in cells (-Xflag).y (
int,optional) – Y position of the floating pane in cells (-Yflag).zoom (
bool,optional) – Zoom the pane (-Zflag).empty (
bool,optional) – Create an empty pane with no command (-Eflag).style (
str,optional) – Style for the floating pane (-sflag).active_border_style (
str,optional) – Border style when the pane is active (-Sflag).inactive_border_style (
str,optional) – Border style when the pane is inactive (-Rflag).message (
str,optional) – Keep the pane open (until a key is pressed) after the command exits, showing thisremain-on-exit-formatmessage (-mflag).keep (
bool,optional) – Keep the pane open until a key is pressed after the command exits (-kflag), using the defaultremain-on-exit-format.
- Returns:
The newly created floating pane.
- Return type:
- Raises:
libtmux.exc.LibTmuxException– If the tmux server is older than 3.7 (new-paneis unavailable).
Examples
>>> from libtmux.common import has_gte_version >>> if has_gte_version("3.7"): ... floating = pane.new_pane(width=40, height=10, shell="sleep 5") ... is_floating = floating.pane_floating_flag ... else: ... is_floating = "1" >>> is_floating '1'
Set pane width.
Set pane height.
Send carriage return to pane.
$ tmux send-keyssend Enter to the pane.- Return type:
-
display_popup(command=None, *, close_on_exit=None, close_on_success=None, close_existing=None, target_client=None, width=None, height=None, x=None, y=None, start_directory=None, title=None, border_lines=None, style=None, border_style=None, environment=None, no_border=None, close_on_any_key=None, no_keys=None)¶method[source]method[source]display_popup(command=None, *, close_on_exit=None, close_on_success=None, close_existing=None, target_client=None, width=None, height=None, x=None, y=None, start_directory=None, title=None, border_lines=None, style=None, border_style=None, environment=None, no_border=None, close_on_any_key=None, no_keys=None)¶
Display a popup overlay via
$ tmux display-popup.Requires tmux 3.2+ and an attached client. Use
ControlModein tests to provide a client.- Parameters:
command (
str,optional) – Shell command to run in the popup.close_on_exit (
bool,optional) – Close popup when command exits (-Eflag).close_on_success (
bool,optional) – Close popup only on success exit code (-EEflag, passing-Etwice).close_existing (
bool,optional) – Close any existing popup on the client (-Cflag).target_client (
str,optional) – Display the popup on this specific client (-cflag). When omitted, tmux selects the client attached to this pane’s session. With multiple clients attached, pass target_client to direct the popup at one of them.width (
int or str, optional) – Popup width (-wflag).height (
int or str, optional) – Popup height (-hflag).x (
int or str, optional) – Popup x position (-xflag).y (
int or str, optional) – Popup y position (-yflag).start_directory (
str or PathLike, optional) – Working directory (-dflag).title (
str,optional) – Popup title (-Tflag). Requires tmux 3.3+.border_lines (
str,optional) – Border line style (-bflag). Requires tmux 3.3+.style (
str,optional) – Popup style (-sflag). Requires tmux 3.3+.border_style (
str,optional) – Border style (-Sflag). Requires tmux 3.3+.environment (
dict,optional) – Environment variables (-eflag). Requires tmux 3.3+.no_border (
bool,optional) – Open the popup without a border (-Bflag). If border_lines is also set, tmux ignores it. Requires tmux 3.3+.close_on_any_key (
bool,optional) – Dismiss the popup on any key press once the inner command has exited (-kflag). Requires tmux 3.6+.no_keys (
bool,optional) – Do not auto-close the popup on any close-trigger keys (-Nflag). Requires tmux 3.6+.
- Return type:
Examples
Not directly testable — popup rendering requires a TTY-backed client. Control-mode provides an attached client for invocation but the popup itself is not visible or verifiable.
>>> with control_mode() as ctl: ... pane.display_popup(command='true', close_on_exit=True)
Paste a buffer into the pane via
$ tmux paste-buffer.- Parameters:
buffer_name (
str,optional) – Name of the buffer to paste (-bflag).delete_after (
bool,optional) – Delete the buffer after pasting (-dflag).linefeed_separator (
bool,optional) – Use newline as the line separator instead of carriage return (-rflag).bracket (
bool,optional) – Use bracketed paste mode (-pflag).separator (
str,optional) – Separator between lines (-sflag).no_vis (
bool,optional) – Paste the buffer’s raw bytes without passing them throughvis(3)escaping (-Sflag). tmux 3.7 escapes pasted content by default; set this to restore the raw behaviour. Requires tmux 3.7+. If used with tmux < 3.7, a warning is issued and the flag is ignored.
- Return type:
Examples
>>> server.set_buffer('pasted_text') >>> pane.paste_buffer()
Pipe pane output to a shell command via
$ tmux pipe-pane.- Parameters:
- Return type:
Examples
>>> pane.pipe('cat >> /tmp/output.txt')
Stop piping:
>>> pane.pipe()
Enter copy mode via
$ tmux copy-mode.- Parameters:
scroll_up (
bool,optional) – Start scrolled up one page (-uflag).exit_on_bottom (
bool,optional) – Exit copy mode when scrolling reaches the bottom of the history (-eflag).mouse_drag (
bool,optional) – Start mouse drag (-Mflag).cancel (
bool,optional) – Cancel copy mode and any other modes (-qflag).page_down (
bool,optional) – Scroll a page down if already in copy mode (-dflag). Requires tmux 3.5+.source_pane (
str,optional) – Source pane whose contents should be displayed in copy mode (-sflag). Lets you scroll/copy from another pane’s history. Requires tmux 3.2+.
- Return type:
Examples
>>> pane.copy_mode()
Enter clock mode via
$ tmux clock-mode.>>> pane.clock_mode()
- Return type:
Show pane numbers via
$ tmux display-panes.Requires an attached client.
Examples
>>> with control_mode() as ctl: ... window.active_pane.display_panes()
Enter buffer chooser via
$ tmux choose-buffer.>>> pane.choose_buffer()
- Return type:
Enter client chooser via
$ tmux choose-client.>>> pane.choose_client()
- Return type:
Enter tree chooser via
$ tmux choose-tree.- Parameters:
sessions_collapsed (
bool,optional) – Start with sessions collapsed (-sflag).windows_collapsed (
bool,optional) – Start with windows collapsed (-wflag).format_string (
str,optional) – Format for each item shown in the chooser (-Fflag).filter_expression (
str,optional) – Filter expression evaluated per item; only items whose filter expands non-zero are shown (-fflag).sort_order (
str,optional) – Sort field (-Oflag).reverse (
bool,optional) – Reverse the sort order (-rflag).zoom (
bool,optional) – Zoom the pane while the chooser is active (-Zflag).
- Return type:
Examples
>>> pane.choose_tree()
Enter customize mode via
$ tmux customize-mode.>>> pane.customize_mode()
- Return type:
Search for a window matching a string via
$ tmux find-window.Opens a choose-tree filtered to matching windows.
- Parameters:
match_string (
str) – String to search for in window names, titles, and content.match_content (
bool,optional) – Match visible pane content (-Cflag).case_insensitive (
bool,optional) – Case-insensitive matching (-iflag).match_name (
bool,optional) – Match window name only (-Nflag).regex (
bool,optional) – Treat match string as a regex (-rflag).match_title (
bool,optional) – Match pane title (-Tflag).
- Return type:
Examples
>>> pane.find_window('sh')
Send the prefix key to the pane via
$ tmux send-prefix.Examples
>>> pane.send_prefix()
Respawn the pane process via
$ tmux respawn-pane.- Parameters:
shell (
str,optional) – Shell command to run in the respawned pane.start_directory (
str or PathLike, optional) – Working directory for the respawned pane (-cflag).environment (
dict,optional) – Environment variables (-eflag).kill (
bool,optional) – Kill the current process before respawning (-kflag). Required if the pane is still active.
- Return type:
Examples
>>> pane = window.split(shell='sleep 1m') >>> pane.respawn(kill=True, shell='sh')
Move this pane to another window via
$ tmux move-pane.Similar to
join()but invokes themove-panecommand directly.- Parameters:
target (
str, Pane, or Window) – Target pane or window to move into.vertical (
bool,optional) – Split vertically (-vflag), default True. False for horizontal (-h).detach (
bool,optional) – Do not switch to the target window (-dflag), default True.full_window (
bool,optional) – Use the full window width/height (-fflag).size (
str or int, optional) – Size for the moved pane (-lflag).before (
bool,optional) – Place the pane before the target (-bflag).
- Return type:
Examples
>>> pane_to_move = window.split(shell='sleep 1m') >>> w2 = session.new_window(window_name='move_target') >>> pane_to_move.move(w2)
Join this pane into another window/pane via
$ tmux join-pane.This is the inverse of
break_pane().- Parameters:
target (
str, Pane, or Window) – Target pane or window to join into.vertical (
bool,optional) – Join vertically (-vflag), default True. Set to False for horizontal (-h).detach (
bool,optional) – Do not switch to the target window (-dflag), default True.full_window (
bool,optional) – Join spanning the full window width/height (-fflag).size (
str or int, optional) – Size for the joined pane (-lflag).before (
bool,optional) – Place the pane before the target (-bflag).
- Return type:
Examples
>>> pane_to_join = window.split(shell='sleep 1m') >>> new_window = pane_to_join.break_pane() >>> pane_to_join.join(window)
Break this pane out into a new window via
$ tmux break-pane.Examples
>>> pane_to_break = window.split(shell='sleep 1m') >>> new_window = pane_to_break.break_pane(window_name='broken') >>> new_window.window_name 'broken'
Swap this pane with another via
$ tmux swap-pane.- Parameters:
target (
str or Pane, optional) –Target pane to swap with. Can be a pane ID string or Pane object. Mutually exclusive with move_up / move_down.
Changed in version 0.56: Now optional; required only when move_up / move_down are not set.
detach (
bool,optional) – Do not change the active pane (-dflag).move_up (
bool,optional) – Swap with the pane above (-Uflag). Mutually exclusive with target and move_down.move_down (
bool,optional) – Swap with the pane below (-Dflag). Mutually exclusive with target and move_up.keep_zoom (
bool,optional) – Keep the window zoomed if it was zoomed (-Zflag).
- Return type:
Examples
>>> pane1 = window.active_pane >>> pane2 = window.split() >>> pane1_id, pane2_id = pane1.pane_id, pane2.pane_id >>> pane1.swap(pane2) >>> pane1.refresh() >>> pane2.refresh()
Reset terminal state and clear pane history.
Sends
send-keys -Randclear-historyto the pane in one targeted tmux command sequence so output cannot land in the freshly-cleared grid between the terminal-state reset and the history clear.Examples
>>> pane.reset() Pane(%... Window(@... ...:..., Session($1 libtmux_...)))
- Return type:
Alias for
pane_title.>>> pane.set_title('test-alias') Pane(...)
>>> pane.title == pane.pane_title True
Typed, converted wrapper around
Pane.pane_at_bottom.>>> pane.pane_at_bottom '1'
>>> pane.at_bottom True
-
__init__(server, active_window_index=None, alternate_saved_x=None, alternate_saved_y=None, bracket_paste_flag=None, buffer_name=None, buffer_sample=None, buffer_size=None, client_activity=None, client_cell_height=None, client_cell_width=None, client_control_mode=None, client_created=None, client_discarded=None, client_flags=None, client_height=None, client_key_table=None, client_last_session=None, client_mode_format=None, client_name=None, client_pid=None, client_prefix=None, client_readonly=None, client_session=None, client_termfeatures=None, client_termname=None, client_termtype=None, client_tty=None, client_uid=None, client_user=None, client_utf8=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=None, pane_dead_signal=None, pane_dead_status=None, pane_dead_time=None, pane_fg=None, pane_flags=None, pane_floating_flag=None, pane_format=None, pane_height=None, pane_id=None, pane_in_mode=None, pane_index=None, pane_input_off=None, pane_last=None, pane_left=None, pane_marked=None, pane_marked_set=None, pane_mode=None, pane_path=None, pane_pb_progress=None, pane_pb_state=None, pane_pid=None, pane_pipe=None, pane_pipe_pid=None, pane_right=None, pane_search_string=None, pane_start_command=None, pane_start_path=None, pane_synchronized=None, pane_tabs=None, pane_title=None, pane_top=None, pane_tty=None, pane_width=None, pane_x=None, pane_y=None, pane_z=None, pane_zoomed_flag=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_format=None, session_group=None, session_group_attached=None, session_group_attached_list=None, session_group_list=None, session_group_many_attached=None, session_group_size=None, session_grouped=None, session_id=None, session_last_attached=None, session_many_attached=None, session_marked=None, session_name=None, session_path=None, session_stack=None, session_windows=None, socket_path=None, start_time=None, synchronized_output_flag=None, uid=None, user=None, version=None, window_active=None, window_active_clients=None, window_active_clients_list=None, window_active_sessions=None, window_active_sessions_list=None, window_activity=None, window_activity_flag=None, window_bell_flag=None, window_bigger=None, window_cell_height=None, window_cell_width=None, window_end_flag=None, window_flags=None, window_format=None, window_height=None, window_id=None, window_index=None, window_last_flag=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_silence_flag=None, window_stack_index=None, window_start_flag=None, window_visible_layout=None, window_width=None, window_zoomed_flag=None, wrap_flag=None, default_option_scope=¶
OptionScope.Pane, default_hook_scope=OptionScope.Pane)method[source]method[source]__init__(server, active_window_index=None, alternate_saved_x=None, alternate_saved_y=None, bracket_paste_flag=None, buffer_name=None, buffer_sample=None, buffer_size=None, client_activity=None, client_cell_height=None, client_cell_width=None, client_control_mode=None, client_created=None, client_discarded=None, client_flags=None, client_height=None, client_key_table=None, client_last_session=None, client_mode_format=None, client_name=None, client_pid=None, client_prefix=None, client_readonly=None, client_session=None, client_termfeatures=None, client_termname=None, client_termtype=None, client_tty=None, client_uid=None, client_user=None, client_utf8=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=None, pane_dead_signal=None, pane_dead_status=None, pane_dead_time=None, pane_fg=None, pane_flags=None, pane_floating_flag=None, pane_format=None, pane_height=None, pane_id=None, pane_in_mode=None, pane_index=None, pane_input_off=None, pane_last=None, pane_left=None, pane_marked=None, pane_marked_set=None, pane_mode=None, pane_path=None, pane_pb_progress=None, pane_pb_state=None, pane_pid=None, pane_pipe=None, pane_pipe_pid=None, pane_right=None, pane_search_string=None, pane_start_command=None, pane_start_path=None, pane_synchronized=None, pane_tabs=None, pane_title=None, pane_top=None, pane_tty=None, pane_width=None, pane_x=None, pane_y=None, pane_z=None, pane_zoomed_flag=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_format=None, session_group=None, session_group_attached=None, session_group_attached_list=None, session_group_list=None, session_group_many_attached=None, session_group_size=None, session_grouped=None, session_id=None, session_last_attached=None, session_many_attached=None, session_marked=None, session_name=None, session_path=None, session_stack=None, session_windows=None, socket_path=None, start_time=None, synchronized_output_flag=None, uid=None, user=None, version=None, window_active=None, window_active_clients=None, window_active_clients_list=None, window_active_sessions=None, window_active_sessions_list=None, window_activity=None, window_activity_flag=None, window_bell_flag=None, window_bigger=None, window_cell_height=None, window_cell_width=None, window_end_flag=None, window_flags=None, window_format=None, window_height=None, window_id=None, window_index=None, window_last_flag=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_silence_flag=None, window_stack_index=None, window_start_flag=None, window_visible_layout=None, window_width=None, window_zoomed_flag=None, wrap_flag=None, default_option_scope=¶OptionScope.Pane, default_hook_scope=OptionScope.Pane) When not a user (custom) option, scope can be implied.
- Parameters:
server (
Server)default_option_scope (
OptionScope|None)default_hook_scope (
OptionScope|None)
- Return type:
Refresh dataclass fields from a single
list-*row.Used by the public
refresh()methods onPane,Window,Session, andClient. Each subclass guards its identity field (pane_id,window_id,session_id,client_name) againstNonebefore delegating here; this base method enforces the same precondition explicitly so the guarantee survivespython -O, where anassertwould be stripped.- Raises:
ValueError– Whenobj_idisNone. Surfaces a clear error underpython -O, matching the contract of the publicrefresh()methods.- Parameters:
- Return type:
Return value for the hook.
- Parameters:
hook (
str)global_ (
bool)scope (
OptionScope|_DefaultOptionScope|None)
- Raises:
- Return type:
Return option value for the target.
todo: test and return True/False for on/off string
- Parameters:
- Raises:
- Return type:
ConvertedValue|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().cmd('new-session', '-d') <libtmux.common.tmux_cmd object at ...>
>>> MyServer()._show_option('exit-unattached', global_=True) False
Return raw option output for target.
- Parameters:
- Raises:
- Return type:
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
Return a dict of options for the target.
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() {...}
Return dict of options for the target.
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
Return a dict of options for the target.
- Parameters:
g (
bool,optional) –Deprecated since version 0.50.0: Use
global_instead.quiet (
bool,optional) –Suppress errors silently (
-qflag).Added in version 0.56.
values_only (
bool,optional) –Return only option values without names (
-vflag).Added in version 0.56.
scope (
OptionScope|_DefaultOptionScope|None)
- Return type:
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 [...]
Resolve tmux_bin from self (Server) or self.server (Session/Window/Pane).
Index of the session’s active window.
Saved cursor X position for the pane’s alternate screen.
Saved cursor Y position for the pane’s alternate screen.
Typed, converted wrapper around
Pane.pane_at_right.>>> pane.pane_at_right '1'
>>> pane.at_right True
"1"when the pane’s terminal has bracketed paste mode enabled.
Name of the buffer.
Sample taken from the start of the buffer’s contents.
Size of the buffer, in bytes.
Time the client last had activity.
Height of one of the client’s terminal cells, in pixels.
Width of one of the client’s terminal cells, in pixels.
"1"when the client is running in control mode.
Time the client was created.
Bytes discarded because the client fell behind.
List of the client’s flags.
Height of the client, in cells.
Name of the key table the client is currently using.
Name of the session the client was attached to before its current one.
Default format string tmux’s client mode (
choose-client) renders each client row with.
Name of the client.
PID of the client process.
"1"while the prefix key has been pressed.
"1"when the client is attached read-only.
Name of the session the client is attached to.
Terminal features tmux detected for the client, if any.
Terminal name of the client.
Terminal type of the client, if available.
Path to the client’s pseudo terminal.
UID of the client process.
User the client process runs as.
"1"when the client supports UTF-8.
Width of the client, in cells.
Bytes written to the client.
Command alias, when listing commands.
Command name, when listing commands.
Command usage string, when listing commands.
List of the configuration files tmux loaded.
Text of the line the cursor sits on in copy mode.
Word under the cursor in copy mode.
Cursor X position in copy mode.
Cursor Y position in copy mode.
Configuration file currently being parsed.
Character at the pane’s cursor position.
"1"when the pane’s cursor is visible.
Cursor X position in the pane.
Cursor Y position in the pane.
Bytes held in the pane’s scrollback history.
Maximum number of scrollback lines the pane keeps.
Lines currently held in the pane’s scrollback history.
"1"when the pane’s terminal is in insert mode.
"1"when the pane’s terminal is in application cursor key mode.
"1"when the pane’s terminal is in application keypad mode.
Index of the last window in the session.
Row number tmux assigns to the entry in the listing.
"1"when the pane’s terminal has all-motion mouse reporting enabled.
"1"when the pane’s terminal has any mouse reporting mode enabled.
"1"when the pane’s terminal has button-event mouse reporting enabled.
"1"when the pane’s terminal reports mouse events in SGR form.
"1"when the pane’s terminal has standard mouse reporting enabled.
Session ID tmux will give the next new session.
"1"when the pane’s terminal is in origin mode.
"1"when this is the active pane of its window.
"1"when the pane touches the bottom of the window.
"1"when the pane touches the left of the window.
"1"when the pane touches the right of the window.
"1"when the pane touches the top of the window.
Bottom edge of the pane, as a window row.
Command running in the pane, if available.
Working directory of the pane, if available.
"1"when the pane’s process has exited and the pane is dead.
Signal that killed the process in a dead pane.
Exit status of the process in a dead pane.
Time the process in a dead pane exited.
Pane flags:
*for the active pane,-for the last used,Zfor zoomed,Ffor floating.
"1"when the pane is floating.
"1"when the format is being evaluated for a pane.
Height of the pane, in cells.
Unique pane ID, e.g.
"%3"(the#Dalias).
Number of modes the pane is in.
Index of the pane within its window (the
#Palias).
"1"when input to the pane is disabled.
"1"when this is the window’s last used pane.
Left edge of the pane, as a window column.
"1"when this pane is the marked pane.
"1"when a marked pane is set on the server.
Name of the mode the pane is in, if any.
Path of the pane; the application running in it can set this.
Progress percentage of the pane’s progress bar; the application running in it can set this.
Pane progress bar state, one of
hidden,normal,error,indeterminate, orpaused; the application running in the pane can set this.
PID of the first process started in the pane.
"1"while the pane’s output is being piped.
PID of the pipe process, if any.
Right edge of the pane, as a window column.
Last search string used in the pane’s copy mode.
Command the pane was started with.
Working directory the pane was started in.
"1"when the pane hassynchronize-panesin effect.
Tab stop positions in the pane.
Title of the pane; the application running in it can set this (the
#Talias).
Top edge of the pane, as a window row.
Path to the pane’s pseudo terminal.
Width of the pane, in cells.
"1"when the pane is zoomed.
Run a hook immediately. Useful for testing.
- Parameters:
hook (
str)scope (
OptionScope|_DefaultOptionScope|None)
- Return type:
Self
Scroll position in copy mode.
Bottom line of the pane’s scroll region.
Top line of the pane’s scroll region.
Search match in the pane’s copy mode, if any.
X position of the end of the copy-mode selection.
Y position of the end of the copy-mode selection.
X position of the start of the copy-mode selection.
Y position of the start of the copy-mode selection.
Time of the session’s last activity.
List of indexes of the session’s windows with alerts.
Number of clients attached to the session.
List of the clients attached to the session.
Time the session was created.
"1"when the format is being evaluated for a session.
Name of the session group the session belongs to.
Number of clients attached to sessions in the session group.
List of the clients attached to sessions in the session group.
List of the sessions in the session group.
"1"when more than one client is attached to sessions in the session group.
Number of sessions in the session group.
"1"when the session belongs to a session group.
Unique session ID, e.g.
"$1".
Time the session was last attached.
"1"when more than one client is attached to the session.
"1"when the session contains the marked pane.
Name of the session (the
#Salias).
Working directory of the session.
Indexes of the session’s windows, most recently used first.
Number of windows in the session.
Set hook for tmux target.
Wraps
$ tmux set-hook <hook> <value>.- Parameters:
- Raises:
- Return type:
Self
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 0clear_existing (
bool) – If True, unset all existing hook values firstscope (
OptionScope|None) – Scope for the hook
- 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 for tmux target.
Wraps
$ tmux set-option <option> <value>.- 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 bygfor global, useglobal_instead.scope (
OptionScope|_DefaultOptionScope|None)
- Raises:
- Return type:
Self
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
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.- Parameters:
hook (
str) – Hook name to queryglobal_ (
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($...)
Return a dict of hooks for the target.
- 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.
- 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($...)
Return option value for the target.
- Parameters:
- Raises:
- Return type:
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
Return all options for the target.
- 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).quiet (
bool,optional) –Suppress errors silently (
-qflag).Added in version 0.56.
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
Path to the tmux server’s socket.
Time the tmux server started.
"1"when the pane’s terminal has synchronized output enabled.
Unset hook for tmux target.
Wraps
$ tmux set-hook -u <hook>/$ tmux set-hook -U <hook>- Parameters:
hook (
str) – hook to unset, e.g. ‘after-show-environment’scope (
OptionScope|_DefaultOptionScope|None)
- Raises:
- Return type:
Self
Unset option for tmux target.
Wraps
$ tmux set-option -u <option>/$ tmux set-option -U <option>- Parameters:
option (
str) – option to unset, e.g. ‘aggressive-resize’scope (
OptionScope|_DefaultOptionScope|None)
- Raises:
- Return type:
Self
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
Version of the running tmux server.
"1"when the window is its session’s current window.
Number of clients viewing the window.
List of the clients viewing the window.
Number of sessions in which the window is the active one.
List of the sessions in which the window is the active one.
Time of the window’s last activity.
"1"when the window has an activity alert.
"1"when the window has a bell alert.
"1"when the window is larger than the client viewing it.
Height of one of the window’s cells, in pixels.
Width of one of the window’s cells, in pixels.
"1"when the window has the highest index in the session.
Window flags, with
#escaped as##(the#Falias).
"1"when the format is being evaluated for a window.
Height of the window, in cells.
Unique window ID, e.g.
"@2".
Index of the window in its session (the
#Ialias).
"1"when the window is the session’s last used one.
Window layout description, ignoring zoomed panes.
"1"when the window is linked across sessions.
Number of sessions the window is linked into.
List of the sessions the window is linked into.
"1"when the window contains the marked pane.
Name of the window (the
#Walias).
X offset into the window when it is larger than the client.
Y offset into the window when it is larger than the client.
Number of panes in the window.
Window flags, with nothing escaped.
"1"when the window has a silence alert.
Index of the window in its session’s most recently used stack.
"1"when the window has the lowest index in the session.
Window layout description, respecting zoomed panes.
Width of the window, in cells.
"1"when the window is zoomed.
"1"when the pane’s terminal wraps at the right margin.
Split window at pane and return newly created
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 verticallypercent (
int,optional) – percentage to occupy with respect to current paneenvironment (
dict,optional) – Environmental variables for new pane. Passthrough to-e.
- Return type:
Notes
Deprecated since version 0.33: Deprecated in favor of
split().
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.
Resize pane, deprecated by
Pane.resize().Deprecated since version 0.28: Deprecated by
Pane.resize().
-