Servers#
Identified by socket path and socket name
May have >1 servers running of tmux at the same time.
Contain Sessions (which contain Windows, which contain Panes)
tmux initializes a server on automatically on first running (e.g. executing tmux
)
- class libtmux.Server(socket_name=None, socket_path=None, config_file=None, colors=None, **kwargs)[source]#
Bases:
EnvironmentMixin
The tmux(1) Server [server_manual].
Server.sessions
[Session
, β¦]Session.windows
[Window
, β¦]Window.panes
[Pane
, β¦]
When instantiated stores information on live, running tmux server.
- Parameters:
Examples
>>> server Server(socket_name=libtmux_test...)
>>> server.sessions [Session($1 ...)]
>>> server.sessions[0].windows [Window(@1 1:..., Session($1 ...)]
>>> server.sessions[0].attached_window Window(@1 1:..., Session($1 ...))
>>> server.sessions[0].attached_pane Pane(%1 Window(@1 1:..., Session($1 ...)))
References
[server_manual]- CLIENTS AND SESSIONS. openbsd manpage for TMUX(1)
βThe tmux server manages clients, sessions, windows and panes. Clients are attached to sessions to interact with them, either when they are created with the new-session command, or later with the attach-session command. Each session has one or more windows linked into it. Windows may be linked to multiple sessions and are made up of one or more panes, each of which contains a pseudo terminal.β
https://man.openbsd.org/tmux.1#CLIENTS_AND_SESSIONS. Accessed April 1st, 2018.
- child_id_attribute = 'session_id'#
Unique child ID used by
TmuxRelationalObject
- formatter_prefix = 'server_'#
Namespace used for
TmuxMappingObject
- socket_name = None#
Passthrough to
[-L socket-name]
- socket_path = None#
Passthrough to
[-S socket-path]
- config_file = None#
Passthrough to
[-f file]
- colors = None#
-2
or-8
- is_alive()[source]#
If server alive or not.
>>> tmux = Server(socket_name="no_exist") >>> assert not tmux.is_alive()
- Return type:
- raise_if_dead()[source]#
Raise if server not connected.
>>> tmux = Server(socket_name="no_exist") >>> try: ... tmux.raise_if_dead() ... except Exception as e: ... print(type(e)) <class 'subprocess.CalledProcessError'>
- Return type:
- cmd(*args, **kwargs)[source]#
Execute tmux command and return output.
Examples
>>> server.cmd('display-message', 'hi') <libtmux.common.tmux_cmd object at ...>
- Return type:
Notes
Changed in version 0.8: Renamed from
.tmux
to.cmd
.- Return type:
- property attached_sessions: List[Session]#
Return active
Session
objects.Examples
>>> server.attached_sessions []
- has_session(target_session, exact=True)[source]#
Return True if session exists.
$ tmux has-session
.- Parameters:
- Raises:
- Return type:
- Return type:
- kill_session(target_session)[source]#
Kill the tmux session with
$ tmux kill-session
, returnself
.- Parameters:
target_session (str, optional) β target_session: str. note this accepts
fnmatch(3)
. βasdfβ will kill βasdfasdβ.- Return type:
- Raises:
- Return type:
- switch_client(target_session)[source]#
$ tmux switch-client
.- Parameters:
target_session (str) β name of the session. fnmatch(3) works.
- Raises:
- Return type:
- attach_session(target_session=None)[source]#
$ tmux attach-session
aka alias:$ tmux attach
.- Parameters:
target_session (str) β name of the session. fnmatch(3) works.
- Raises:
- Return type:
- new_session(session_name=None, kill_session=False, attach=False, start_directory=None, window_name=None, window_command=None, *args, **kwargs)[source]#
Return
Session
from$ tmux new-session
.Uses
-P
flag to print session info,-F
for return formatting returns new Session object.$ tmux new-session -d
will create the session in the background$ tmux new-session -Ad
will move to the session name if it already exists. todo: make an option to handle this.- Parameters:
session_name (str, optional) β
$ tmux new-session -s <session_name>
attach (bool, optional) β
create session in the foreground.
attach=False
is equivalent to:$ tmux new-session -d
kill_session (bool, optional) β Kill current session if
$ tmux has-session
. Useful for testing workspaces.start_directory (str, optional) β specifies the working directory in which the new session is created.
window_name (str, optional) β
$ tmux new-session -n <window_name>
window_command (str) β execute a command on starting the session. 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.
- Return type:
- Raises:
Examples
Sessions can be created without a session name (0.14.2+):
>>> server.new_session() Session($2 2)
Creating them in succession will enumerate IDs (via tmux):
>>> server.new_session() Session($3 3)
With a session_name:
>>> server.new_session(session_name='my session') Session($4 my session)
- Return type:
- property sessions: QueryList[Session]#
Sessions belonging server.
Can be accessed via
.sessions.get()
and.sessions.filter()
- property windows: QueryList[Window]#
Windows belonging server.
Can be accessed via
.windows.get()
and.windows.filter()
- property panes: QueryList[Pane]#
Panes belonging server.
Can be accessed via
.panes.get()
and.panes.filter()
- _list_panes()[source]#
Return list of panes in
dict
form.Retrieved from
$ tmux(1) list-panes
stdout.The
list
is derived fromstdout
inutil.tmux_cmd
which wrapssubprocess.Popen
.Deprecated since version 0.16.
- getenv(name)[source]#
Show environment variable
$ tmux show-environment -t [session] <name>
.Return the value of a specific variable if the name is specified.
New in version 0.13.
- show_environment()[source]#
Show environment
$ tmux show-environment -t [session]
.Return dict of environment variables for the session.
Changed in version 0.13: Removed per-item lookups. Use
libtmux.common.EnvironmentMixin.getenv()
.
- _list_windows()[source]#
Return list of windows in
dict
form.Retrieved from
$ tmux(1) list-windows
stdout.The
list
is derived fromstdout
incommon.tmux_cmd
which wrapssubprocess.Popen
.Deprecated since version 0.16.
- _update_windows()[source]#
Update internal window data and return
self
for chainability.Deprecated since version 0.16.
- Return type:
- property _sessions: List[Dict[str, Any]]#
Property / alias to return
_list_sessions()
.Deprecated since version 0.16.