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-go latest

Session

Session is one materialized tmux session record. It is normally returned by Server.Snapshot, Server.Session, or Session.Refresh. A zero Session is not a usable tmux target.

Source and package
Qualified name
tmux.Session
Package
tmux
Distribution
github.com/libtmux/libtmux-go/tmux
Source
tmux/model.go
Other languages
Perlclass ErlangPowerShellcmdlet Juliastruct Elixirstruct Haskell Common Lispclass PythonRubyLuaTypeScriptRustJavaC#C++SwiftKotlinScalaOCamlF#module Clojurefunction
struct tmux.Session

Description#

What is on here

A Session is a record read at one moment, and the methods that act on tmux address the session by its stable SessionID. They fall into the groups below.

Identity and refreshing
A record does not update: Session.Refresh looks the session up again by its stable SessionID and returns a new record, leaving the receiver as it was. SessionFromEnv finds the session that holds the environment's pane. Equality compares the stable ID and the tmux server that produced the record.
Fields on the record
The typed accessors read tmux's session formats from the record in hand and never query tmux. Each returns false as its second result when the value is absent, empty, or malformed, and some formats need tmux 3.6 or later. The raw expansions come back as a FormatValues, where FormatValues.Raw tells an absent field from a present empty one.
Raw
Windows and panes
A record from a snapshot holds its windows and panes, and reading them queries nothing; a record from a lookup, a refresh, or Server.NewSession carries no relations and reports false. The resolvers read live state and the search methods ask tmux, and a search takes a TmuxFilter, where nil omits tmux's -f expression. A window made or selected here comes back freshly materialized, and selecting one is session-scoped: it makes no promise about clients attached to other sessions.
Create
Running a command
Run starts a command in a new window with a terminal, waits for it, and returns its exit status and the screen it left; a nonzero status is a result, not an error. Start returns once the command is under way, and if the Running it returns is never waited on, the window it created is never removed. Cmd instead sends a raw tmux subcommand targeted at the session.
Renaming and ending
Rename returns a new record, and it rejects an invalid name before running tmux with an error matching ErrInvalidRequest. Killing the session removes its winlinks and detaches ordinary attached clients, destroying any window left with no links; a window kill removes one window from every session it is linked into. KillWith can instead destroy every other session or only clear alerts. A completed kill is a CommandError only when it wrote to stderr, so a nonzero exit without stderr is ignored.
Options, hooks, and environment
Typed reads include inherited values, and a failed read is returned rather than answered with zero values. A write by name reaches an option the typed setters do not cover, and each known option has a typed setter that SessionOptionValues pairs with its accessor. The environment is the session's own, apart from the server's global one: reading one variable reports false for a missing or hidden entry, and unsetting deletes an entry where removing marks it for removal from the environment of new processes.
Read options
Typed setters, for example
Read hooks
Clients and connections
Attach hands the caller's terminal to the session and blocks until detach or context cancellation. The other client methods act on every client attached to the session, except one that switches tmux's current client to it. Opening control mode needs tmux 3.7 and returns a Connection that the caller must close; a session already bound to a connection can open neither another nor a notification stream.
Terminal
Every attached client
Current client

Members132#

Parent objects1#

  • Server method Server returns the immutable configured handle that produced the session.

Collections and queries4#

  • Windows method Windows returns newly allocated shallow copies of this snapshot record's winlink views, and reports whether the receiver carries relations at all.
  • Panes method Panes returns newly allocated shallow copies of this snapshot record's pane views, and reports whether the receiver carries relations at all.
  • SearchWindows method SearchWindows returns this session's winlinks selected by tmux's live -f expression. A nil filter omits -f and a nonnil empty filter sends an explicit expression. The session's stable identity limits the projection.
  • SearchPanes method SearchPanes returns this session's pane views selected by tmux's live -f expression. A nil filter omits -f and a nonnil empty filter sends an explicit expression. The session's stable identity limits the projection.

Common operations42#

  • NewWindow method NewWindow creates a winlink in the receiver session. Attach selects it as that session's current window; it is not a guarantee about clients attached to other sessions. The returned Window is freshly materialized in the receiver's exact session context, including when its stable WindowID is linked elsewhere.
  • Kill method Kill destroys the receiver session and removes its winlinks. Ordinary attached clients detach; on tmux 3.6 or later, clients carrying no-detach-on-destroy move to another session when one exists. A window with no remaining links and all of that window's panes are also destroyed. The materialized receiver is not refreshed. Only stderr makes a completed command a CommandError; nonzero exits without stderr are ignored. Transport errors are delivery-ambiguous. Kill is equivalent to Session.KillWith with a zero SessionKillRequest.
  • Rename method Rename changes the receiver session's name and returns a canonical freshly materialized Session. If the command succeeds but refresh fails, it returns the receiver with that error. A transport or context error can be delivery-ambiguous; no rollback is attempted. Invalid names are rejected before execution and match ErrInvalidRequest.
  • Hooks method Hooks returns a freshly decoded, caller-owned view of known hooks at this stable session target, including inherited values. A read failure is returned rather than answered with zero values.
  • ID method ID returns the stable tmux identity of this session.
  • Name method Name returns tmux #{session_name} as string from this Session's materialized session-scoped fields.
  • Attached method Attached returns tmux #{session_attached} as int from this Session's materialized session-scoped fields.
  • Options method Options returns a freshly decoded, caller-owned view of known options at this stable session target, including inherited values. A read failure is returned rather than answered with zero values; context errors propagate. Each returned accessor names the setter that writes it, so SessionOptionValues.Mouse pairs with Session.SetMouse.
  • SetOption method SetOption stores a session option at this stable session target without refreshing existing models. Completed failures are secret-safe option errors; cancellation does not prove tmux did not accept the mutation.
  • UnsetOption method UnsetOption unsets a session option at this stable session target without refreshing models. UnsetPanes is invalid at this scope; cancellation does not prove the unset was not accepted.
  • SetHook method SetHook stores a session hook at this stable session target without refreshing models. Completed failures are secret-safe option errors; cancellation does not prove tmux did not accept the mutation.
  • ShowEnvironment method ShowEnvironment returns an owned session-scoped non-hidden tmux environment. Completed command failures return an empty map unless strict errors are enabled. Externally injected multiline entries return ErrMalformedEnvironment because tmux's multi-entry output does not frame continuation lines. Decode errors are compatible with ErrMalformedEnvironment and return no partial map.
  • SetEnvironment method SetEnvironment stores a value in this session's tmux environment, targeted by its stable SessionID.
  • UnsetEnvironment method UnsetEnvironment deletes a value from this session's tmux environment, targeted by its stable SessionID.
  • RawOption method RawOption returns one exact session option value at this stable session target. A successful string is caller-owned; ok reports presence, and a completed failure is returned rather than normalized. An unindexed empty array is indistinguishable from an empty scalar; use Options for typed array presence.
  • Created method Created returns tmux #{session_created} as time.Time from this Session's materialized session-scoped fields.
  • DetachClients method DetachClients detaches every client attached to the session identified by this handle's stable ID. A nonnil ShellCommand is run after detaching.
  • ActiveWindow method ActiveWindow returns this session's sole active winlink from the materialized snapshot. It never queries tmux; use Session.ResolveActiveWindow for live state.
  • UnsetHook method UnsetHook removes every matching session hook index at this stable session target without refreshing models. Completed failures are secret-safe option errors; cancellation does not prove the unset was accepted.
  • ActivePane method ActivePane returns the active pane in this session's materialized active window. It never queries tmux; use Session.ResolveActivePane for live state.
  • Refresh method Refresh performs a canonical live lookup without mutating the receiver.
  • NextWindow method NextWindow makes the next winlink current in the receiver session and returns that freshly materialized session-specific Window. The selection is session-scoped; it does not promise focus for clients attached to other sessions. A transport or context error can be delivery-ambiguous and no rollback is attempted. Command or refresh failure returns a zero Window.
  • PreviousWindow method PreviousWindow makes the previous winlink current in the receiver session and returns that freshly materialized session-specific Window. The selection is session-scoped; it does not promise focus for clients attached to other sessions. A transport or context error can be delivery-ambiguous and no rollback is attempted. Command or refresh failure returns a zero Window.
  • LastWindow method LastWindow makes the receiver session's previously selected winlink current and returns that freshly materialized session-specific Window. The selection is session-scoped; it does not promise focus for clients attached to other sessions. A transport or context error can be delivery-ambiguous and no rollback is attempted. Command or refresh failure returns a zero Window because this navigation operation cannot identify the selected view reliably without refresh.
  • RemoveEnvironment method RemoveEnvironment marks a variable for removal from new process environments for this stable session target.
  • WindowCount method WindowCount returns tmux #{session_windows} as int from this Session's materialized session-scoped fields.
  • Path method Path returns tmux #{session_path} as string from this Session's materialized session-scoped fields.
  • SelectWindow method SelectWindow makes one winlink current in the receiver session and returns that freshly materialized session-specific Window. WindowID is combined with the receiver SessionID, because a WindowID alone does not distinguish linked views. The selection is session-scoped; it does not promise focus for clients attached to other sessions.
  • Cmd method Cmd executes a tmux subcommand targeted to the session's stable ID.
  • Lock method Lock locks every client attached to the session identified by this handle's stable ID. Cancellation does not prove that tmux did not lock a client.
  • GetEnvironment method GetEnvironment returns one non-hidden session environment entry for this stable session target. A missing or hidden variable reports ok false.
  • SetHooks method SetHooks applies indexed session hook commands in ascending order at this handle's stable session target. With ClearExisting it confirms clearing first, stops at the first failure without rollback, and reports confirmed partial progress. Cancellation may follow accepted commands and cannot disprove their delivery.
  • RunHook method RunHook asks tmux to run one session hook directly at this stable target. It intentionally performs no racy liveness preflight after validation. Completed failures are secret-safe option errors; cancellation does not prove execution did not occur.
  • KillWindow method KillWindow destroys one stable window. When Target and Index are nil it selects the receiver session's current window, and Index selects a winlink in that session. A nonnil Target is forwarded as unrestricted tmux target syntax and may select a window in another session. The selected stable window is removed from every session and its panes are destroyed. Affected sessions preserve their current selection unless this window was current, in which case they select another. A session left without windows is destroyed; Session.Kill describes how tmux handles its clients.
  • SwitchClient method SwitchClient switches tmux's current client to the session identified by this handle's stable ID.
  • Group method Group returns tmux #{session_group} as string from this Session's materialized session-scoped fields.
  • Grouped method Grouped returns tmux #{session_grouped} as bool from this Session's materialized session-scoped fields.
  • LastAttached method LastAttached returns tmux #{session_last_attached} as time.Time from this Session's materialized session-scoped fields.
  • ResolveActivePane method ResolveActivePane returns the active pane in this session's active window, read live. It lists that session's panes rather than taking a whole-server snapshot, because a pane row already carries which window is active. It returns SnapshotLookupError cardinality errors, which match ErrNotFound when nothing was found.
  • OpenControl method OpenControl opens terminal control-mode transport to the receiver's daemon. The returned connection owns its lanes and must be closed. A receiver already bound to a connection cannot be rebound. Acquisition requires tmux 3.7 before any control client is started.
  • OpenNotifications method OpenNotifications starts an owned notification stream attached to the receiver. It does not change the receiver's transport or expose control commands. A connection-bound receiver returns ErrConnectionRequiresProcess.
  • Run method Run starts command in a new window of this session, waits for it to finish, and reports its exit status and what its terminal showed. It is [os/exec] for a program that needs a terminal: the command runs with a tty, so it sees isatty, colour, and a width, and what comes back is the screen tmux rendered rather than the bytes the program wrote. That screen holds a bounded history; see RunResult.Lines. For a large output, have the command write it to a file, or follow it with Running.StreamTo.

Other members85#

Guides#

Pages that discuss Session.

In other ports#

A tmux session

Equivalents of A tmux session in other languages
Language Equivalent
Python libtmux.Session
Ruby LibTmux::Session
Lua libtmux.Session
PowerShell LibTmux\Get-TmuxSession This cmdlet reads and returns shared .NET LibTmux.Session objects. Child windows and panes require further acquisition.
Julia LibTmux.SessionSnapshot SessionSnapshot holds captured session data. Actions use its SessionRef, a typed identity bound to an observed daemon generation.
Erlang #tmux_model:session{}
Elixir LibTmux.Session Session is an immutable observation. Fields not captured read as :unloaded.
Haskell No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing.
Common Lisp libtmux:session session is an immutable captured entity. The same name also has a relation accessor with a distinct public identity.
TypeScript session.Session
Rust session.Session
Java io.github.libtmux.Session
Clojure libtmux.core/sessions! Acquires a vector of captured session maps. The session value is a map, not a wrapper class.
Kotlin io.github.libtmux.kotlin.Session
Scala io.github.libtmux.scaladsl.Session
C# LibTmux.Session
F# LibTmux.FSharp.Session This F# module builds deferred child queries from a shared .NET LibTmux.Session and its server association. Query.list acquires their results from tmux.
C++ libtmux::Session
Swift Session
OCaml Libtmux.Session.t
Perl LibTmux::Session A captured read-only entity; explicit Server operations accept its stable identity.
Esc

Type to search.

Reference previewOpen reference