Sessions¶
-
class
libtmux.
Session
(server=None, **kwargs)[source] Bases:
libtmux.common.TmuxMappingObject
,libtmux.common.TmuxRelationalObject
,libtmux.common.EnvironmentMixin
Holds
Window
objects.Parameters: server ( Server
) –References
[1] - 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.
-
child_id_attribute
= 'window_id' unique child ID key for
TmuxRelationalObject
-
formatter_prefix
= 'session_' namespace used
TmuxMappingObject
-
cmd
(*args, **kwargs)[source] Return
server.cmd()
.Returns: Return type: server.cmd
Notes
Changed in version 0.8: Renamed from
.tmux
to.cmd
.
-
attach_session
()[source] Return
$ tmux attach-session
aka alias:$ tmux attach
.
-
kill_session
()[source] $ tmux kill-session
.
-
switch_client
()[source] Switch client to this session.
Raises: exc.LibTmuxException –
-
rename_session
(new_name)[source] Rename session and return new
Session
object.Parameters: new_name (str) – new session name Returns: Return type: Session
Raises: exc.BadSessionName –
-
new_window
(window_name=None, start_directory=None, attach=True, window_index='', window_shell=None)[source] Return
Window
from$ tmux 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
.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) –
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.
Returns: Return type:
-
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.Parameters: target_window (str, optional) – window to kill
-
property
_windows
Property / alias to return
Session._list_windows()
.
-
list_windows
()[source] Return a list of
Window
from thetmux(1)
session.Returns: Return type: Window
-
property
windows
Property / alias to return
Session.list_windows()
.
-
property
children
Alias
windows
forTmuxRelationalObject
-
select_window
(target_window)[source] Return
Window
selected via$ tmux select-window
.Parameters: window (str) – target_window
also ‘last-window’ (-l
), ‘next-window’ (-n
), or ‘previous-window’ (-p
)Returns: Return type: Window
Notes
-
property
attached_pane
Return active
Pane
object.
-
set_option
(option, value, _global=False)[source] Set option
$ tmux set-option <option> <value>
.Parameters: Raises: Notes
-
show_options
(option=None, _global=False)[source] Return a dict of options for the window.
For familiarity with tmux, the option
option
param forwards to pick a single option, forwarding toSession.show_option()
.Parameters: Returns: Return type: Notes
Uses
_global
for keyword name instead ofglobal
to avoid colliding with reserved keyword.
-
show_option
(option, _global=False)[source] Return a list of options for the window.
Parameters: Returns: Return type: Raises: Notes
Uses
_global
for keyword name instead ofglobal
to avoid colliding with reserved keyword.Test and return True/False for on/off string.
-
clear
() → None. Remove all items from D.[source]
-
find_where
(attrs)[source] Return object on first match.
Changed in version 0.4: Renamed from
.findWhere
to.find_where
.
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.[source]
-
get_by_id
(id)[source] Return object based on
child_id_attribute
.Parameters: val (str) – Returns: Return type: object Notes
Based on .get() from backbone.js.
-
items
() → a set-like object providing a view on D’s items[source]
-
keys
()[source] Return list of keys.
-
pop
(k[, d]) → v, remove specified key and return the corresponding value.[source] If key is not found, d is returned if given, otherwise KeyError is raised.
-
popitem
() → (k, v), remove and return some (key, value) pair[source] as a 2-tuple; but raise KeyError if D is empty.
-
remove_environment
(name)[source] Remove environment variable
$ tmux set-environment -r <name>
.Parameters: name (str) – the environment variable name. such as ‘PATH’.
-
set_environment
(name, value)[source] Set environment
$ tmux set-environment <name> <value>
.Parameters:
-
setdefault
(k[, d]) → D.get(k,d), also set D[k]=d if k not in D[source]
-
show_environment
(name=None)[source] Show environment
$ tmux show-environment -t [session] <name>
.Return dict of environment variables for the session or the value of a specific variable if the name is specified.
Parameters: name (str) – the environment variable name. such as ‘PATH’. Returns: environmental variables in dict, if no name, or str if name entered. Return type: str or dict
-
unset_environment
(name)[source] Unset environment variable
$ tmux set-environment -u <name>
.Parameters: name (str) – the environment variable name. such as ‘PATH’.
-
update
([E, ]**F) → None. Update D from mapping/iterable E and F.[source] If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
-
values
() → an object providing a view on D’s values[source]