Prerelease This site documents an alpha of libtmux. Its structure, URLs and APIs are subject to change.

session.Session.cmd

Rust

View as Markdown

Module
session
Declared in
Session
Package
libtmux
Source
crates/libtmux/src/session.rs
Other languages
PythonTypeScriptGo Java .NET C++ Swift
cmd ( self , command : Command ) → Result<CommandResult, Error>
method [source]
method [source]
cmd

Run a raw tmux command against this session.

The escape hatch for anything this crate does not wrap. -t is placed after the subcommand for you, because tmux stops reading flags at the first positional: a target appended after one is taken as text, and the command then succeeds having acted on something else.

A non-zero exit status comes back in the CommandResult rather than as an error, the same as crate::Server::cmd .

Errors

Returns an error when the process cannot be started, captured, or awaited.

In other ports Run a tmux command addressed at a session

Examples

let guard = libtmux::test::TestServer::new().await?;
let session = guard.server().new_session("raw").await?;
let result = session
.cmd(libtmux::Command::new("display-message").arg("-p").arg("#{session_name}"))
.await?;
assert_eq!(result.stdout_lossy().trim(), "raw");
guard.shutdown().await?;
>>> session.cmd('new-window', '-P').stdout[0]
'libtmux...:....0'

From raw output to an enriched Window object:

>>> Window.from_window_id(window_id=session.cmd(
... 'new-window', '-P', '-F#{window_id}').stdout[0], server=session.server)
Window(@... ...:..., Session($1 libtmux_...))
await session.cmd("rename-session", ["--", "renamed"]);

0 declared, 0 inherited

Esc

Type to search.