Skip to content

Commit 25e45fd

Browse files
committed
docs(Session.cmd): Add examples
1 parent 01ab013 commit 25e45fd

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/libtmux/session.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,25 @@ def panes(self) -> QueryList["Pane"]:
140140
# Command
141141
#
142142
def cmd(self, cmd: str, *args: t.Any) -> tmux_cmd:
143-
"""Execute tmux subcommand against target session. See :meth:`server.cmd`.
143+
"""Execute tmux subcommand within session context.
144+
145+
Automatically adds ``-t`` for object's session ID to the command. Pass ``-t``
146+
in args to override.
147+
148+
Examples
149+
--------
150+
>>> session.cmd('new-window', '-P').stdout[0]
151+
'libtmux...:....0'
152+
153+
From raw output to an enriched `Window` object:
154+
155+
>>> Window.from_window_id(window_id=session.cmd(
156+
... 'new-window', '-P', '-F#{window_id}').stdout[0], server=session.server)
157+
Window(@... ...:..., Session($1 libtmux_...))
144158
145159
Returns
146160
-------
147-
:class:`server.cmd`
161+
:meth:`server.cmd`
148162
149163
Notes
150164
-----

0 commit comments

Comments
 (0)