Skip to content

Commit 53ce1c5

Browse files
committed
docs(README): Direct usage examples
1 parent f9245be commit 53ce1c5

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

README.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
5858
Server(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+
69112
List sessions:
70113

71114
```python

0 commit comments

Comments
 (0)