Server.windows
Every window on the server, including each placement of a linked window.
Source and package
-
Description#
Save this complete program as
windows.ts. With Bun 1.4.2 or newer, tmux 3.2a or newer, andlibtmuxinstalled, runbun run windows.ts. It creates and stops a private tmux server. A failed operation or cleanup exits with an error; a cleanup error names the retained socket directory.Examples#
import { strict as assert } from "node:assert";import { mkdtemp, readdir, rm } from "node:fs/promises";import { tmpdir } from "node:os";import { join } from "node:path";import { Server, MultipleMatchesError } from "libtmux";const directory = await mkdtemp(join(tmpdir(), "ltx-example-"));const server = new Server({socketPath: join(directory, "tmux.sock"),configFile: "/dev/null",timeoutMs: 5_000,});const failures: unknown[] = [];try {const session = await server.newSession({name: "home",windowName: "editor",shellCommand: "cat",});const guest = await server.newSession({name: "guest",windowName: "shell",shellCommand: "cat",});const window = await session.newWindow({ name: "logs", shellCommand: "cat" });await window.link({ session: guest });const windows = await server.windows();const logs = windows.where({ name: "logs" });assert.equal(logs.count(), 2);console.log("logs placements:", logs.count());try {logs.one();throw new Error("Expected a linked window lookup to be ambiguous");} catch (error) {if (!(error instanceof MultipleMatchesError)) throw error;console.log("ambiguous:", error.code);}const placed = logs.one({ session: { is: { name: "home" } } });assert.equal(placed.id, window.id);console.log("selected placement:", placed.session?.name);console.log("linked sessions:",placed.linkedSessions.map((item) => item.name).sort().join(", "),);} catch (error) {failures.push(error);} finally {try {if ((await readdir(directory)).includes("tmux.sock")) await server.kill();await rm(directory, { recursive: true });} catch (error) {failures.push(new Error(`Cleanup failed; inspect ${directory}`, { cause: error }));}}if (failures.length > 0) throw new AggregateError(failures, "Example failed");
Guides#
Pages that discuss windows.
In other ports#
List the server's windows
| Language | Equivalent |
|---|---|
| Python | libtmux |
| Ruby | Lib |
| Lua | libtmux |
| PowerShell | Lib Use the -Server parameter set to acquire window placements across all sessions. |
| Julia | Lib windows with a Snapshot reads every captured physical window. Use windowlinks for session placements. |
| Elixir | Lib Returns a Selection of every captured physical window. window_links/1 lists session placements. |
| Rust | server |
| Go | tmux |
| Java | io |
| Kotlin | io |
| Scala | io |
| C# | Lib |
| F# | Lib Builds a deferred query for placements across all sessions. Query.list acquires the results; a linked window appears once for each session placement. |
| C++ | libtmux:: |
| Swift | Server |