Skip to content

Commit d12ce99

Browse files
committed
Add properties and traversing page
1 parent 1cf5acd commit d12ce99

File tree

2 files changed

+212
-2
lines changed

2 files changed

+212
-2
lines changed

doc/properties.rst

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,137 @@
44
Properties
55
==========
66

7-
In tmux,
7+
Get access to the data attributions behind tmux sessions, windows and panes.
8+
9+
open two terminals:
10+
11+
terminal one: start tmux in a seperate terminal::
12+
13+
$ tmux
14+
15+
.. NOTE::
16+
17+
Make sure you have :ref:`libtmux installed <installation>`::
18+
19+
pip install libtmux
20+
21+
To upgrade:
22+
23+
pip install -U libtmux
24+
25+
terminal two, ``python`` or ``ptpython`` if you have it::
26+
27+
$ python
28+
29+
import tmux::
30+
31+
import tmux
32+
33+
attach default tmux :class:`libtmux.Server` to ``t``::
34+
35+
>>> t = libtmux.Server();
36+
>>> t
37+
<libtmux.server.Server object at 0x10edd31d0>
38+
39+
Session
40+
-------
41+
42+
get our ``session`` object::
43+
44+
>>> session = t.sessions[0]
45+
46+
>>> session
47+
Session($0 libtmux)
48+
49+
quick access to basic attributes::
50+
51+
>>> session.name
52+
u'libtmux'
53+
54+
>>> session.id
55+
u'$0'
56+
57+
>>> session.width
58+
u'213'
59+
60+
>>> session.height
61+
u'114'
62+
63+
to see all attributes for a session::
64+
65+
>>> session._info.keys()
66+
[u'session_height', u'session_windows', u'session_width', u'session_id', u'session_created', u'session_attached', u'session_grouped', u'session_name']
67+
68+
>>> session._info
69+
{u'session_height': u'114', u'session_windows': u'3', u'session_width': u'213', u'session_id': u'$0', u'session_created': u'1464905357', u'session_attached': u'1', u'session_grouped': u'0', u'session_name': u'libtmux'}
70+
71+
72+
some may conflict with python API, to access them, you can use ``.get()``, to get the count
73+
of sessions in a window::
74+
75+
>>> session.get('session_windows')
76+
u'3'
77+
78+
Windows
79+
-------
80+
81+
The same concepts apply for window::
82+
83+
>>> window = session.attached_window
84+
85+
>>> window
86+
Window(@2 2:docs, Session($0 libtmux))
87+
88+
basics::
89+
90+
>>> window.name
91+
u'docs'
92+
93+
>>> window.id
94+
u'@2'
95+
96+
>>> window.height
97+
u'114'
98+
99+
>>> window.width
100+
u'213'
101+
102+
everything available::
103+
104+
>>> window._info
105+
{u'window_panes': u'4', u'window_active': u'1', u'window_height': u'114', u'window_activity_flag': u'0', u'window_width': u'213', u'session_id': u'$0', u'window_id': u'@2', u'window_layout': u'dad5,213x114,0,0[213x60,0,0,4,213x53,0,61{70x53,0,61,5,70x53,71,61,6,71x53,142,61,7}]', u'window_silence_flag': u'0', u'window_index': u'2', u'window_bell_flag': u'0', u'session_name': u'libtmux', u'window_flags': u'*', u'window_name': u'docs'}
106+
107+
>>> window.keys()
108+
[u'window_panes', u'window_active', u'window_height', u'window_activity_flag', u'window_width', u'session_id', u'window_id', u'window_layout', u'window_silence_flag', u'window_index', u'window_bell_flag', u'session_name', u'window_flags', u'window_name']
109+
110+
Panes
111+
-----
112+
113+
get our pane::
114+
115+
>>> pane = window.attached_pane
116+
117+
>>> pane
118+
Pane(%5 Window(@2 2:docs, Session($0 libtmux)))
119+
120+
basics::
121+
122+
>>> pane.current_command
123+
u'python'
124+
125+
>>> pane.height
126+
u'53'
127+
128+
>>> pane.width
129+
u'70'
130+
131+
>>> pane.index
132+
u'1'
133+
134+
everything::
135+
136+
>>> pane._info
137+
{u'alternate_saved_x': u'0', u'alternate_saved_y': u'0', u'cursor_y': u'47', u'cursor_x': u'0', u'pane_in_mode': u'0', u'insert_flag': u'0', u'keypad_flag': u'0', u'cursor_flag': u'1', u'pane_current_command': u'python', u'window_index': u'2', u'history_size': u'216', u'scroll_region_lower': u'52', u'keypad_cursor_flag': u'0', u'history_bytes': u'38778', u'pane_active': u'1', u'pane_dead': u'0', u'pane_synchronized': u'0', u'window_id': u'@2', u'pane_index': u'1', u'pane_width': u'70', u'mouse_any_flag': u'0', u'mouse_button_flag': u'0', u'window_name': u'docs', u'pane_current_path': u'/Users/me/work/python/libtmux/doc', u'pane_tty': u'/dev/ttys007', u'pane_title': u'Python REPL (ptpython)', u'session_id': u'$0', u'alternate_on': u'0', u'mouse_standard_flag': u'0', u'wrap_flag': u'1', u'history_limit': u'2000', u'pane_pid': u'37172', u'pane_height': u'53', u'session_name': u'libtmux', u'scroll_region_upper': u'0', u'pane_id': u'%5'}
138+
139+
>>> pane._info.keys()
140+
[u'alternate_saved_x', u'alternate_saved_y', u'cursor_y', u'cursor_x', u'pane_in_mode', u'insert_flag', u'keypad_flag', u'cursor_flag', u'pane_current_command', u'window_index', u'history_size', u'scroll_region_lower', u'keypad_cursor_flag', u'history_bytes', u'pane_active', u'pane_dead', u'pane_synchronized', u'window_id', u'pane_index', u'pane_width', u'mouse_any_flag', u'mouse_button_flag', u'window_name', u'pane_current_path', u'pane_tty', u'pane_title', u'session_id', u'alternate_on', u'mouse_standard_flag', u'wrap_flag', u'history_limit', u'pane_pid', u'pane_height', u'session_name', u'scroll_region_upper', u'pane_id']

doc/traversing.rst

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,81 @@
44
Traversing
55
==========
66

7-
In tmux,
7+
libtmux offers you a handy way to move around the hierachy of sessions,
8+
windows and panes in tmux.
9+
10+
open two terminals:
11+
12+
terminal one: start tmux in a seperate terminal::
13+
14+
$ tmux
15+
16+
.. NOTE::
17+
18+
Make sure you have :ref:`libtmux installed <installation>`::
19+
20+
pip install libtmux
21+
22+
To upgrade:
23+
24+
pip install -U libtmux
25+
26+
terminal two, ``python`` or ``ptpython`` if you have it::
27+
28+
$ python
29+
30+
import tmux::
31+
32+
import tmux
33+
34+
attach default tmux :class:`libtmux.Server` to ``t``::
35+
36+
>>> t = libtmux.Server();
37+
>>> t
38+
<libtmux.server.Server object at 0x10edd31d0>
39+
40+
get first session :class:`Session` to `session`::
41+
42+
>>> session = t.sessions[0]
43+
>>> session
44+
Session($0 libtmux)
45+
46+
get a list of sessions::
47+
48+
>>> t.sessions
49+
[Session($0 libtmux), Session($1 tmuxp)]
50+
51+
iterate through sessions in a server::
52+
53+
>>> for sess in t.sessions:
54+
... print(sess)
55+
56+
Session($0 libtmux)
57+
Session($1 tmuxp)
58+
59+
grab a :class:`Window` from a session::
60+
61+
>>> session.windows[0]
62+
Window(@1 1:libtmux, Session($0 libtmux))
63+
64+
grab the currently focused window from session:
65+
66+
>>> session.attached_window
67+
Window(@2 2:docs, Session($0 libtmux))
68+
69+
grab the currently focused :class:`Pane` from session::
70+
71+
>>> session.attached_pane
72+
Pane(%5 Window(@2 2:docs, Session($0 libtmux)))
73+
74+
assign the attached pane to ``p``::
75+
76+
>>> p = session.attached_pane
77+
78+
access the window/server of a pane::
79+
80+
>>> p.window
81+
Window(@2 2:docs, Session($0 libtmux))
82+
83+
>>> p.server
84+
<libtmux.server.Server object at 0x104191a10>

0 commit comments

Comments
 (0)