# command.CommandChain

- **Module:** command
- **Package:** libtmux
- **Language:** Rust
- **Kind:** struct
- **Source:** https://github.com/libtmux/libtmux-rs/blob/f0e37052c232636b61d095817046e6bfc8f2ca40/crates/libtmux/src/command.rs#L324
- **Page:** https://libtmux.org/en/rs/latest/reference/command-commandchain/

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

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.

## Example

```rust
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""#,
);
```

## Example

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

```rust
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""#,
);
```

## Members

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