print(shell_ret('du -sh'))232K .
All capture and list functions accept SSH kwargs to target a remote machine: use host for an SSH alias, or ip + user + optional keyfile.
Run shell command locally or over ssh (use host for alias, or ip/user/keyfile)
ssh: Could not resolve hostname hack: nodename nor servname provided, or not known
Set the default number of lines to capture from tmux history
def pane(
n:int=None, # Number of scrollback lines to capture, in addition to visible area (None uses default_tmux_lines, which is 500 if not otherwise set)
pane:int | str=None, # Pane number to capture from (accepts both integers for window IDs and "%{int}" for global pane IDs)
session:str=None, # Session name to target
window:int=None, # Window number to target
capture_output:bool=True, text:bool=True, ret:bool=True, host:str=None, # Optional SSH Host
ip:str=None, # Optional SSH IP
user:str=None, # Optional SSH user
keyfile:str=None, # Optional SSH keyfile
):
Grab the tmux history in plain text
def list_panes(
session:str=None, # Session name to list panes from
window:int=None, # Window number to list panes from
capture_output:bool=True, text:bool=True, ret:bool=True, host:str=None, # Optional SSH Host
ip:str=None, # Optional SSH IP
user:str=None, # Optional SSH user
keyfile:str=None, # Optional SSH keyfile
):
List panes for a session/window (or current if none specified)
0: [97x26] [history 1963/2000, 868118 bytes] %56
1: [90x26] [history 405/2000, 158948 bytes] %81
2: [97x25] [history 458/2000, 115648 bytes] %44 (active)
3: [90x25] [history 14/2000, 18831 bytes] %77
def panes(
session:str=None, # Session name to target
window:int=None, # Window number to target
n:int=None, # Number of scrollback lines to capture
capture_output:bool=True, text:bool=True, ret:bool=True, host:str=None, # Optional SSH Host
ip:str=None, # Optional SSH IP
user:str=None, # Optional SSH user
keyfile:str=None, # Optional SSH keyfile
):
Grab history from all panes in a session/window
List all windows in a session
0: bash* (4 panes) [188x52] [layout 37fe,188x52,0,0[188x26,0,0{97x26,0,0,56,90x26,98,0,81},188x25,0,27{97x25,0,27,44,90x25,98,27,77}]] @10 (active)
def windows(
session:str=None, # Session name to target
n:int=None, # Number of scrollback lines to capture
capture_output:bool=True, text:bool=True, ret:bool=True, host:str=None, # Optional SSH Host
ip:str=None, # Optional SSH IP
user:str=None, # Optional SSH user
keyfile:str=None, # Optional SSH keyfile
):
Grab history from all panes in all windows of a session as {'win_num:name': {pane_num: content}}
List all tmux sessions
10: 1 windows (created Tue Apr 21 12:39:41 2026) (attached)
23: 1 windows (created Mon May 11 10:38:18 2026)
bgtmux-369d887b92: 1 windows (created Fri May 1 13:29:21 2026)
bgtmux-cd962474af: 1 windows (created Fri May 1 14:00:25 2026)
Grab history from all panes in all windows of all sessions as {session: {'win_num:name': {pane_num: content}}}
windows() and sessions() return nested dicts. Use flatten_dict to search them as (path, content) tuples, where path identifies the session/window/pane source. The path string uses // separators showing the hierarchy, e.g. "mysession//0:bash//1" means session "mysession", window 0 named "bash", pane 1.
For example, find error lines across all tmux history:
Or find panes containing a command you remember:
Flatten nested dict into list of (key_path, value) tuples