Skip to content

Latest commit

 

History

History
102 lines (72 loc) · 1.71 KB

traversal.md

File metadata and controls

102 lines (72 loc) · 1.71 KB

(traversal)=

Traversal

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

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

Open two terminals:

Terminal one: start tmux in a seperate terminal:

$ tmux

Terminal two, python or ptpython if you have it:

$ python

Import libtmux:

import libtmux

Attach default tmux {class}~libtmux.Server to t:

>>> import libtmux
>>> t = libtmux.Server();
>>> t
<libtmux.server.Server object at ...>

Get first session {class}~libtmux.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 {class}~libtmux.Window from a session:

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

Grab the currently focused window from session:

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

Grab the currently focused {class}Pane from session:

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

Assign the attached {class}~libtmux.Pane to p:

>>> p = session.attached_pane

Access the window/server of a pane:

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

>>> p.server
<libtmux.server.Server object at ...>