Skip to content

Commit 88ee7cd

Browse files
committed
chore(tmux_cmd): Improve docstring, add doctest
1 parent fee8d4c commit 88ee7cd

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/libtmux/common.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,20 +187,21 @@ def getenv(self, name: str) -> Optional[t.Union[str, bool]]:
187187

188188

189189
class tmux_cmd:
190-
""":term:`tmux(1)` command via :py:mod:`subprocess`.
190+
"""Run any :term:`tmux(1)` command through :py:mod:`subprocess`.
191191
192192
Examples
193193
--------
194-
.. code-block:: python
194+
Create a new session, check for error:
195195
196-
proc = tmux_cmd('new-session', '-s%' % 'my session')
196+
>>> proc = tmux_cmd(f'-L{server.socket_name}', 'new-session', '-d', '-P', '-F#S')
197+
>>> if proc.stderr:
198+
... raise exc.LibTmuxException(
199+
... 'Command: %s returned error: %s' % (proc.cmd, proc.stderr)
200+
... )
201+
...
197202
198-
if proc.stderr:
199-
raise exc.LibTmuxException(
200-
'Command: %s returned error: %s' % (proc.cmd, proc.stderr)
201-
)
202-
203-
print('tmux command returned %s' % proc.stdout)
203+
>>> print(f'tmux command returned {" ".join(proc.stdout)}')
204+
tmux command returned 2
204205
205206
Equivalent to:
206207

0 commit comments

Comments
 (0)