Core Library0.xAPI Reference

Choose documentation 3

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

struct libtmux-rs latest

CommandChain

Several tmux commands dispatched as one tmux a \; b invocation.

Source and package
Qualified name
libtmux::command::CommandChain
Module
command
Package
libtmux
Source
crates/libtmux/src/command.rs
struct command.CommandChain

Description#

tmux reads a bare ; argv element as a command boundary and a \; element as a literal semicolon. Command lowers every trailing ; a caller supplies, so a boundary cannot come from an argument; it comes from this type, which owns the separator. That is what makes a chain safe to build from untrusted values.

A chain is one dispatch: one process, one exit status, one merged stdout. tmux runs the sequence up to the first failure and drops the remainder, and the merged result is the same whichever member failed, so a chain reports one outcome rather than one per command. Use it to cut round trips when the commands succeed or fail as a unit; dispatch separately when you need to know which one failed.

Examples#

use libtmux::{Command, CommandChain};
let chain = CommandChain::new(Command::new("send-keys").arg("-t").arg("%1"))
.then(Command::new("rename-window").arg("-t").arg("@1").arg("edit"));
assert_eq!(chain.command_count(), 2);
assert_eq!(
chain.summary().to_string(),
r#""send-keys" "-t" "%1" ; "rename-window" "-t" "@1" "edit""#,
);

A literal semicolon stays an argument, and renders quoted so it is not mistaken for the boundary beside it:

use libtmux::{Command, CommandChain};
let chain = CommandChain::new(Command::new("display-message").arg(";"))
.then(Command::new("list-sessions"));
assert_eq!(
chain.summary().to_string(),
r#""display-message" ";" ; "list-sessions""#,
);

Members4#

  • command_count method Return the number of commands in the chain, always at least one.
  • new method Start a chain from its first command.
  • summary method Build a bounded, sanitized summary of the whole chain.
  • then method Append one command, to run after the previous one succeeds.

Guides#

Pages that discuss CommandChain.

Esc

Type to search.

Reference previewOpen reference