Expand description
tmux-companion: one daemon that draws the tmux status bar, and the tools around a tmux server that a plugin manager used to provide.
Most people want the binary:
cargo install --locked tmux-companion
tmux-companion doctorand the manual, man tmux-companion, or the
README for what it
does.
§The library
The same crate is a library, for a program that wants a part of what the binary does without running the binary for it. Three parts are meant to be used from outside, and the documentation shows only those:
- Asking the daemon.
daemon::Daemonsends one request to a runningtmux-companion serverand returns its answer, with the request and response types and each command’s arguments inproto. It’s blocking, needs no async runtime, and never starts or replaces a daemon. - Parsing and drawing.
segments::gitparsesgit status --porcelain=v2 --branchintosegments::git::GitStatusand renders it as a segment;tmux::formatbuilds tmux style strings and turns them into ANSI for a terminal;segments::networkis the arithmetic behind a transfer rate;keyroute::spelltranslates key names from nvim, fzf, zsh, nano and Claude Code into tmux’s spelling. None of these touch tmux or a socket. - Session snapshots.
sessions::Snapshotis a whole tmux server as data:sessions::capturebuilds one from tmux’s own listings,sessions::renderandsessions::parsewrite and read the file format,sessions::storekeeps generations of them,sessions::portablemoves one between machines, andsessions::importreads what tmux-resurrect saved.
use tmux_companion::segments::git::GitStatus;
let porcelain = "\
# branch.oid 1f2e3d4c5b6a
# branch.head main
# branch.upstream origin/main
# branch.ab +2 -0
1 .M N... 100644 100644 100644 aaaa bbbb src/lib.rs
? notes.txt
";
let status = GitStatus::parse_porcelain_v2(porcelain);
assert_eq!(status.branch, "main");
assert_eq!(status.ahead, 2);
assert_eq!(status.unstaged.modified, 1);
assert_eq!(status.untracked, 1);§Stability
The parts above follow semver: before 1.0 a breaking change to them bumps the minor version and has a line in the changelog. Everything else in the crate is the binary’s own code. It’s public so the integration tests can link against it, it’s hidden from these docs and it changes whenever the binary needs it to, in any release.
The library pulls in everything the binary uses, tokio and ratatui included; there are no feature flags to trim it yet.
Modules§
- daemon
- Asking a running tmux-companion daemon for a segment, from another program.
- keyroute
- keys that tmux and the apps in its panes both want: what each layer binds, and where they collide
- proto
- The daemon’s protocol: one JSON
Requestline in, one JSONResponseline out, and one arguments struct per command. - segments
- One module per thing the status bar can draw.
- sessions
- Snapshots of the whole tmux server, and the generations they are kept in.
- tmux
- Everything that knows about tmux’s own formatting language.