Usage

libtmux provides convenient access to move around the hierarchy of sessions, windows and panes in tmux.

This is done by libtmux’s object abstraction of targets (the -t argument) and the permanent internal ID’s tmux gives to objects.

Open two terminals:

Terminal one: start tmux in a separate terminal:

$ tmux

Terminal two, python or ptpython if you have it:

$ python

Import libtmux:

import libtmux

Attach default tmux Server to t:

>>> import libtmux
>>> t = libtmux.Server();
>>> t
Server(socket_path=/tmp/tmux-.../default)

Get first session Session to session:

>>> session = server.sessions[0]
>>> session
Session($1 ...)

Get a list of sessions:

>>> server.sessions
[Session($1 ...), Session($0 ...)]

Iterate through sessions in a server:

>>> for sess in server.sessions:
...     print(sess)
Session($1 ...)
Session($0 ...)

Grab a Window from a session:

>>> session.windows[0]
Window(@1 ...:..., Session($1 ...))

Grab the currently focused window from session:

>>> session.active_window
Window(@1 ...:..., Session($1 ...))

Grab the currently focused Pane from session:

>>> session.active_pane
Pane(%1 Window(@1 ...:..., Session($1 ...)))

Assign the attached Pane to p:

>>> p = session.active_pane

Access the window/server of a pane:

>>> p = session.active_pane
>>> p.window
Window(@1 ...:..., Session($1 ...))

>>> p.server
Server(socket_name=libtmux_test...)