@@ -108,7 +108,7 @@ First, we can grab a {class}`Server`.
108
108
>> > import libtmux
109
109
>> > server = libtmux.Server()
110
110
>> > server
111
- < libtmux.server.Server object at 0x 7fbd622c1dd0 >
111
+ < libtmux.server.Server object at ... >
112
112
```
113
113
114
114
:::{tip}
@@ -139,14 +139,15 @@ We can list sessions with {meth}`Server.list_sessions`:
139
139
140
140
``` python
141
141
>> > server.list_sessions()
142
- [Session($ 3 foo ), Session($ 1 libtmux )]
142
+ [Session($ ... ... ), Session($ ... ... )]
143
143
```
144
144
145
145
This returns a list of {class}` Session ` objects you can grab. We can
146
146
find our current session with:
147
147
148
148
``` python
149
149
>> > server.list_sessions()[0 ]
150
+ Session($ ... ... )
150
151
```
151
152
152
153
However, this isn't guaranteed, libtmux works against current tmux information, the
@@ -157,20 +158,24 @@ so {meth}`Server.get_by_id` and {meth}`Server.find_where` exists as a lookup.
157
158
158
159
tmux sessions use the ` $[0-9] ` convention as a way to identify sessions.
159
160
160
- ` $3 ` is whatever the ID ` list_sessions() ` returned above.
161
+ ` $1 ` is whatever the ID ` list_sessions() ` returned above.
161
162
162
163
``` python
163
- >> > server.get_by_id(' $3 ' )
164
- Session($ 3 foo )
164
+ >> > server.get_by_id(' $1 ' )
165
+ Session($ ... ... )
165
166
```
166
167
167
168
You may ` session = server.get_by_id('$<yourId>') ` to use the session object.
168
169
169
170
## Get session by name / other properties
170
171
171
172
``` python
173
+ # Just for setting up the example:
174
+ >> > server.sessions[0 ].rename_session(' foo' )
175
+ Session($ ... foo)
176
+
172
177
>> > server.find_where({ " session_name" : " foo" })
173
- Session($ 3 foo)
178
+ Session($ ... foo)
174
179
```
175
180
176
181
With ` find_where ` , pass in a dict and return the first object found. In
@@ -181,7 +186,13 @@ through Windows and Panes, respectively.
181
186
So you may now use:
182
187
183
188
``` python
189
+ # Prepping the example:
190
+ >> > server.sessions[0 ].rename_session(' foo' )
191
+ Session($ ... foo)
192
+
184
193
>> > session = server.find_where({ " session_name" : " foo" })
194
+ >> > session
195
+ Session($ ... foo)
185
196
```
186
197
187
198
to give us a ` session ` object to play with.
@@ -195,7 +206,7 @@ Let's make a {meth}`Session.new_window`, in the background:
195
206
196
207
``` python
197
208
>> > session.new_window(attach = False , window_name = " ha in the bg" )
198
- Window(@ 8 2 :ha in the bg, Session($ 3 foo ))
209
+ Window(@ ... ... :ha in the bg, Session($ ... ... ))
199
210
```
200
211
201
212
So a few things:
@@ -214,7 +225,7 @@ Let's delete that window ({meth}`Session.kill_window`).
214
225
Method 1: Use passthrough to tmux's ` target ` system.
215
226
216
227
``` python
217
- >> > session.kill_window(" ha in " )
228
+ >> > session.kill_window(window.id )
218
229
```
219
230
220
231
The window in the bg dissappeared. This was the equivalent of
@@ -234,21 +245,26 @@ should have history, so navigate up with the arrow key.
234
245
235
246
``` python
236
247
>> > session.new_window(attach = False , window_name = " ha in the bg" )
237
- Window(@ 11 3 :ha in the bg, Session($ 3 foo ))
248
+ Window(@ ... ... :ha in the bg, Session($ ... ... ))
238
249
```
239
250
240
251
Try to kill the window by the matching id ` @[0-9999] ` .
241
252
242
253
``` python
254
+ # Setup
243
255
>> > session.new_window(attach = False , window_name = " ha in the bg" )
244
- Window(@ 12 3 :ha in the bg, Session($ 3 foo))
256
+ Window(@ ... ... :ha in the bg, Session($ ... ... ))
257
+
258
+ >> > session.kill_window(' ha in the bg' )
245
259
```
246
260
247
261
In addition, you could also ` .kill_window ` direction from the {class}` Window `
248
262
object:
249
263
250
264
``` python
251
265
>> > window = session.new_window(attach = False , window_name = " check this out" )
266
+ >> > window
267
+ Window(@ ... ... :check this out, Session($ ... ... ))
252
268
```
253
269
254
270
And kill:
@@ -266,7 +282,7 @@ Now that we know how to create windows, let's use one. Let's use {meth}`Session.
266
282
to grab our current window.
267
283
268
284
``` python
269
- >> > window = session.attached_window()
285
+ >> > window = session.attached_window
270
286
```
271
287
272
288
` window ` now has access to all of the objects inside of {class}` Window ` .
@@ -275,7 +291,7 @@ Let's create a pane, {meth}`Window.split_window`:
275
291
276
292
``` python
277
293
>> > window.split_window(attach = False )
278
- Pane(% 23 Window(@ 10 1 :bar , Session($ 3 foo )))
294
+ Pane(% ... Window(@ ... ... : ... , Session($ ... ... )))
279
295
```
280
296
281
297
Powered up. Let's have a break down:
@@ -288,7 +304,7 @@ Also, since you are aware of this power, let's commemorate the experience:
288
304
289
305
``` python
290
306
>> > window.rename_window(' libtmuxower' )
291
- Window(@ 10 1 :libtmuxower , Session($ 3 foo ))
307
+ Window(@ ... ... : ... , Session($ ... ... ))
292
308
```
293
309
294
310
You should have noticed {meth}` Window.rename_window ` renamed the window.
@@ -313,6 +329,7 @@ can also use the `.select_*` available on the object, in this case the pane has
313
329
314
330
``` python
315
331
>> > pane.select_pane()
332
+ Pane(% ... Window(@ ... ... :... , Session($ ... ... )))
316
333
```
317
334
318
335
``` {eval-rst}
0 commit comments