Properties¶
Get access to the data attributes behind tmux sessions, windows and panes.
This is done through accessing the formats available in list-sessions
,
list-windows
and list-panes
.
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)
Session¶
Get the Session
object:
>>> session = server.sessions[0]
>>> session
Session($1 libtmux_...)
Quick access to basic attributes:
>>> session.session_name
'libtmux_...'
>>> session.session_id
'$1'
To see all attributes for a session:
from libtmux.neo import Obj
>>> sorted(list(Obj.__dataclass_fields__.keys()))
['session_attached', 'session_created', ...]
>>> session.session_windows
'...'
Windows¶
The same concepts apply for Window
:
>>> window = session.active_window
>>> window
Window(@1 ...:..., Session($1 ...))
Basics:
>>> window.window_name
'...'
>>> window.window_id
'@1'
>>> window.window_height
'...'
>>> window.window_width
'...'
Use attribute access for details not accessible via properties:
>>> window.window_panes
'1'
Panes¶
Get the Pane
:
>>> pane = window.active_pane
>>> pane
Pane(%1 Window(@1 ...:..., Session($1 libtmux_...)))
Basics:
>>> pane.pane_current_command
'...'
>>> type(pane.pane_current_command)
<class 'str'>
>>> pane.pane_height
'...'
>>> pane.pane_width
'...'
>>> pane.pane_index
'0'