SessionsΒΆ
- class libtmux.Session[source]ΒΆ
Bases:
Obj
,EnvironmentMixin
tmux(1) Session [session_manual].
Holds
Window
objects.- Parameters:
server (
Server
) β
Examples
>>> session Session($1 ...)
>>> session.windows [Window(@1 ...:..., Session($1 ...)]
>>> session.active_window Window(@1 ...:..., Session($1 ...))
>>> session.active_pane Pane(%1 Window(@1 ...:..., Session($1 ...)))
References
[session_manual]- tmux session. openbsd manpage for TMUX(1).
βWhen tmux is started it creates a new session with a single window and displays it on screenβ¦β
βA session is a single collection of pseudo terminals under the management of tmux. Each session has one or more windows linked to it.β
https://man.openbsd.org/tmux.1#DESCRIPTION. Accessed April 1st, 2018.
- property windows: QueryList[Window]ΒΆ
Windows contained by session.
Can be accessed via
.windows.get()
and.windows.filter()
- property panes: QueryList[Pane]ΒΆ
Panes contained by sessionβs windows.
Can be accessed via
.panes.get()
and.panes.filter()
- cmd(cmd, *args, target=None)[source]ΒΆ
Execute tmux subcommand within session context.
Automatically binds target by adding
-t
for objectβs session ID to the command. Passtarget
to keyword arguments to override.Examples
>>> session.cmd('new-window', '-P').stdout[0] 'libtmux...:....0'
From raw output to an enriched Window object:
>>> Window.from_window_id(window_id=session.cmd( ... 'new-window', '-P', '-F#{window_id}').stdout[0], server=session.server) Window(@... ...:..., Session($1 libtmux_...))
- Parameters:
- Return type:
server.cmd()
Notes
Changed in version 0.34: Passing target by
-t
is ignored. Usetarget
keyword argument instead.Changed in version 0.8: Renamed from
.tmux
to.cmd
.
- set_option(option, value, _global=False)[source]ΒΆ
Set option
$ tmux set-option <option> <value>
.- Return type:
- Parameters:
- Raises:
exc.OptionError β
Notes
- show_options(_global=False)[source]ΒΆ
Return dict of options for the session.
- Return type:
- Parameters:
_global (bool, optional) β Pass
-g
flag for global variable (server-wide)- Return type:
Notes
Uses
_global
for keyword name instead ofglobal
to avoid colliding with reserved keyword.
- show_option(option, _global=False)[source]ΒΆ
Return option value for the target session.
- Return type:
- Parameters:
- Return type:
- Raises:
exc.OptionError β
Notes
Uses
_global
for keyword name instead ofglobal
to avoid colliding with reserved keyword.Test and return True/False for on/off string.
- select_window(target_window)[source]ΒΆ
Select window and return the selected window.
- Return type:
- Parameters:
- Return type:
Notes
- attach(_exit=None, _flags=None)[source]ΒΆ
Return
$ tmux attach-session
aka alias:$ tmux attach
.Examples
>>> session = server.new_session()
>>> session not in server.attached_sessions True
- kill(all_except=None, clear=None)[source]ΒΆ
Kill
Session
, closes linked windows and detach all clients.$ tmux kill-session
.- Return type:
- Parameters:
Examples
Kill a session:
>>> session_1 = server.new_session()
>>> session_1 in server.sessions True
>>> session_1.kill()
>>> session_1 not in server.sessions True
Kill all sessions except the current one:
>>> one_session_to_rule_them_all = server.new_session()
>>> other_sessions = server.new_session( ... ), server.new_session()
>>> all([w in server.sessions for w in other_sessions]) True
>>> one_session_to_rule_them_all.kill(all_except=True)
>>> all([w not in server.sessions for w in other_sessions]) True
>>> one_session_to_rule_them_all in server.sessions True
- rename_session(new_name)[source]ΒΆ
Rename session and return new
Session
object.- Return type:
- Parameters:
new_name (str) β new session name
- Raises:
- new_window(window_name=None, *, start_directory=None, attach=False, window_index='', window_shell=None, environment=None, direction=None, target_window=None)[source]ΒΆ
Create new window, returns new
Window
.By default, this will make the window active. For the new window to be created and not set to current, pass in
attach=False
.- Return type:
- Parameters:
window_name (str, optional) β
start_directory (str, optional) β working directory in which the new window is created.
attach (bool, optional) β make new window the current window after creating it, default True.
window_index (str) β create the new window at the given index position. Default is empty string which will create the window in the next available position.
window_shell (str, optional) β
execute a command on starting the window. The window will close when the command exits.
Note
When this command exits the window will close. This feature is useful for long-running processes where the closing of the window upon completion is desired.
direction (WindowDirection, optional) β Insert window before or after target window (tmux 3.2+).
target_window (str, optional) β Used by
Window.new_window()
to specify the target window.versionchanged: (..) β 0.28.0:
attach
default changed fromTrue
toFalse
.
See also
Examples
>>> window_initial = session.new_window(window_name='Example') >>> window_initial Window(@... 2:Example, Session($1 libtmux_...)) >>> window_initial.window_index '2'
>>> window_before = session.new_window( ... window_name='Window before', direction=WindowDirection.Before) >>> window_initial.refresh() >>> window_before Window(@... 1:Window before, Session($1 libtmux_...)) >>> window_initial Window(@... 3:Example, Session($1 libtmux_...))
>>> window_after = session.new_window( ... window_name='Window after', direction=WindowDirection.After) >>> window_initial.refresh() >>> window_after.refresh() >>> window_after Window(@... 3:Window after, Session($1 libtmux_...)) >>> window_initial Window(@... 4:Example, Session($1 libtmux_...)) >>> window_before Window(@... 1:Window before, Session($1 libtmux_...))
- Returns:
The newly created window.
- Return type:
- Parameters:
- kill_window(target_window=None)[source]ΒΆ
Close a tmux window, and all panes inside it,
$ tmux kill-window
.Kill the current window or the window at
target-window
. removing it from any sessions to which it is linked.
- property id: str | NoneΒΆ
Alias of
Session.session_id
.>>> session.id '$1'
>>> session.id == session.session_id True
- property name: str | NoneΒΆ
Alias of
Session.session_name
.>>> session.name 'libtmux_...'
>>> session.name == session.session_name True
- property attached_pane: Pane | NoneΒΆ
Return the active
Pane
object.Notes
Deprecated since version 0.31: Deprecated in favor of
active_pane()
.
- property attached_window: WindowΒΆ
Return the active
Window
object.Notes
Deprecated since version 0.31: Deprecated in favor of
active_window()
.
- attach_session()[source]ΒΆ
Return
$ tmux attach-session
aka alias:$ tmux attach
.- Return type:
Notes
Deprecated since version 0.30: Deprecated in favor of
attach()
.
- kill_session()[source]ΒΆ
Destroy session.
- Return type:
Notes
Deprecated since version 0.30: Deprecated in favor of
kill()
.
- get(key, default=None)[source]ΒΆ
Return key-based lookup. Deprecated by attributes. :rtype:
Any
Deprecated since version 0.16: Deprecated by attribute lookup.e.g.
session['session_name']
is now accessed viasession.session_name
.
- get_by_id(session_id)[source]ΒΆ
Return window by id. Deprecated in favor of
windows.get()
. :rtype:Optional
[Window
]Deprecated since version 0.16: Deprecated by
windows.get()
.
- where(kwargs)[source]ΒΆ
Filter through windows, return list of
Window
. :rtype:List
[Window
]Deprecated since version 0.16: Deprecated by
windows.filter()
.
- find_where(kwargs)[source]ΒΆ
Filter through windows, return first
Window
. :rtype:Optional
[Window
]Deprecated since version 0.16: Slated to be removed in favor of
windows.get()
.
- _list_windows()[source]ΒΆ
Return list of windows (deprecated in favor of
windows
). :rtype:List
[Dict
[str
,Any
]]Deprecated since version 0.16: Slated to be removed in favor of
windows
.
- property _windows: List[Dict[str, Any]]ΒΆ
Property / alias to return
Session._list_windows()
.Deprecated since version 0.16: Slated to be removed in favor of
windows
.
- list_windows()[source]ΒΆ
Return a list of
Window
from thetmux(1)
session. :rtype:List
[Window
]Deprecated since version 0.16: Slated to be removed in favor of
windows
.
- property children: QueryList[Window]ΒΆ
Was used by TmuxRelationalObject (but thatβs longer used in this class).
Deprecated since version 0.16: Slated to be removed in favor of
windows
.
- __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)[source]ΒΆ
- 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) β
- Return type:
None
- getenv(name)[source]ΒΆ
Show environment variable
$ tmux show-environment -t [session] <name>
.Return the value of a specific variable if the name is specified. :rtype:
Union
[str
,bool
,None
]New in version 0.13.
- show_environment()[source]ΒΆ
Show environment
$ tmux show-environment -t [session]
.Return dict of environment variables for the session. :rtype:
Dict
[str
,Union
[bool
,str
]]Changed in version 0.13: Removed per-item lookups. Use
libtmux.common.EnvironmentMixin.getenv()
.- Returns:
environmental variables in dict, if no name, or str if name entered.
- Return type: