@@ -53,8 +53,8 @@ Connect to a live tmux session:
5353
5454``` python
5555>> > import libtmux
56- >> > s = libtmux.Server()
57- >> > s
56+ >> > svr = libtmux.Server()
57+ >> > svr
5858Server(socket_path = / tmp/ tmux- ... / default)
5959```
6060
@@ -66,6 +66,49 @@ current tmux server / session / window pane.
6666[ ptpython ] : https://github.com/prompt-toolkit/ptpython
6767[ ipython ] : https://ipython.org/
6868
69+ Run any tmux command, respective of context:
70+
71+ Honors tmux socket name and path:
72+
73+ ``` python
74+ >> > server = Server(socket_name = ' libtmux_doctest' )
75+ >> > server.cmd(' display-message' , ' hello world' )
76+ < libtmux... >
77+ ```
78+
79+ New session:
80+
81+ ``` python
82+ >> > server.cmd(' new-session' , ' -d' , ' -P' , ' -F#{session_id} ' ).stdout[0 ]
83+ ' $2'
84+ ```
85+
86+ ``` python
87+ >> > session.cmd(' new-window' , ' -P' ).stdout[0 ]
88+ ' libtmux...:2.0'
89+ ```
90+
91+ Time for some tech, direct to a rich, ` Window ` object:
92+
93+ ``` python
94+ >> > Window.from_window_id(window_id = session.cmd(' new-window' , ' -P' , ' -F#{window_id} ' ).stdout[0 ], server = session.server)
95+ Window(@ 2 2 :... , Session($ 1 libtmux_... ))
96+ ```
97+
98+ Create a pane from a window:
99+
100+ ``` python
101+ >> > window.cmd(' split-window' , ' -P' , ' -F#{pane_id} ' ).stdout[0 ]
102+ ' %2'
103+ ```
104+
105+ Magic, directly to a ` Pane ` :
106+
107+ ``` python
108+ >> > Pane.from_pane_id(pane_id = session.cmd(' split-window' , ' -P' , ' -F#{pane_id} ' ).stdout[0 ], server = session.server)
109+ Pane(% ... Window(@ 1 1 :... , Session($ 1 libtmux_... )))
110+ ```
111+
69112List sessions:
70113
71114``` python
@@ -87,43 +130,57 @@ Direct lookup:
87130Session($ 1 ... )
88131```
89132
90- Find session by dict lookup :
133+ Filter sesions :
91134
92135``` python
93136>> > server.sessions[0 ].rename_session(' foo' )
94137Session($ 1 foo)
95- >> > server.sessions.filter(session_name = " foo" )[0 ]
138+ >> > server.sessions.filter(session_name = " foo" )
139+ [Session($ 1 foo)]
140+ >> > server.sessions.get(session_name = " foo" )
96141Session($ 1 foo)
97142```
98143
99144Control your session:
100145
101146``` python
102- >> > session.rename_session( ' foo ' )
103- Session($ 1 foo )
104- >> > session.new_window( attach = False , window_name = " ha in the bg " )
105- Window( @ 2 2 :ha in the bg, Session( $ 1 foo) )
106- >> > session.kill_window( " ha in " )
147+ >> > session
148+ Session($ 1 ... )
149+
150+ >> > session.rename_session( ' my-session ' )
151+ Session( $ 1 my - session )
107152```
108153
109154Create new window in the background (don't switch to it):
110155
111156``` python
112- >> > session.new_window(attach = False , window_name = " ha in the bg" )
113- Window(@ 2 2 :ha in the bg, Session($ 1 ... ))
157+ >> > bg_window = session.new_window(attach = False , window_name = " ha in the bg" )
158+ >> > bg_window
159+ Window(@ ... 2 :ha in the bg, Session($ 1 ... ))
160+
161+ # Session can search the window
162+ >> > session.windows.filter(window_name__startswith = " ha" )
163+ [Window(@ ... 2 :ha in the bg, Session($ 1 ... ))]
164+
165+ # Directly
166+ >> > session.windows.get(window_name__startswith = " ha" )
167+ Window(@ ... 2 :ha in the bg, Session($ 1 ... ))
168+
169+ # Clean up
170+ >> > bg_window.kill()
114171```
115172
116173Close window:
117174
118175``` python
119- >> > w = session.attached_window
176+ >> > w = session.active_window
120177>> > w.kill()
121178```
122179
123180Grab remaining tmux window:
124181
125182``` python
126- >> > window = session.attached_window
183+ >> > window = session.active_window
127184>> > window.split_window(attach = False )
128185Pane(% 2 Window(@ 1 1 :... Session($ 1 ... )))
129186```
0 commit comments