Read tmux objects
Needs libtmux for PowerShell 0.x Install
The cmdlets return native objects from
libtmux for .NET. Inspect them
with Get-Member, select their properties and pass them to other cmdlets.
Choose a server
Create an endpoint with New-TmuxServer -SocketPath or -SocketName, then
pipe it to a read command. Creating it does no I/O.
- No socket parameter: tmux picks the server: the one
TMUXnames inside a tmux pane, otherwise its default socket. - Environment:
LIBTMUX_SOCKET_PATH(-S) orLIBTMUX_SOCKET(-L) chooses a socket for such an endpoint, the path first. A blank value counts as unset, and a parameter beats both. The endpoint reads them when it is made. Connect-TmuxServer: discovers an unmaterialized endpoint and returns its connected replacement. A connected handle is returned unchanged.
| Command | Typed owner accepted from the pipeline | Output |
|---|---|---|
Connect-TmuxServer¶ | LibTmux.Server | LibTmux.Server |
Get-TmuxSnapshot¶ | LibTmux.Server | Replacement LibTmux.Server |
Get-TmuxSession¶ | LibTmux.Server | LibTmux.Session objects |
Get-TmuxWindow¶ | LibTmux.Server or LibTmux.Session | LibTmux.Window objects |
Get-TmuxPane¶ | LibTmux.Server, LibTmux.Session, or LibTmux.Window | LibTmux.Pane objects |
These commands read tmux explicitly.
Select objects
-Idselects a literal tmux identifier, such as$0,@1or%2. Use single quotes for a session ID.-Nameis also accepted by session and window commands.- Selectors compare ordinally and distinguish case. They do not expand wildcards, and combined selectors must all match.
- An unmatched selector emits no objects and is not an error. Wrap a pipeline
in
@(...)when its count matters. - Owners bind by their native type. Property names on another object do not bind from the pipeline.
- Tab completion for
-Nameand-Idoffers values from a captured server, session or window, never from tmux. Capture first withGet-TmuxSnapshot; an uncaptured owner offers none. The command still checks current state when you run it.
For more filtering, use Where-Object after acquisition. For reusable
criteria, use New-TmuxQuery with the local
Select-TmuxPane,
Select-TmuxWindow or
Select-TmuxSession.
Get-TmuxQueryField lists the fields.
For a fresh query, pass an endpoint and a query document to
Invoke-TmuxQuery. It emits matching
native objects; -AsResult keeps the result and its complete captured graph,
including an empty selection.
Get-TmuxQueryPlan shows source
evaluation, local residuals and fallback reasons before execution, with no I/O.
The query guide has the details.
Snapshots
Get-TmuxSnapshot defaults to -Depth Panes. Shallower depths are
Server, Sessions, and
Windows. It returns a replacement graph and leaves
the input handle and earlier snapshots unchanged. Even -Depth Server performs
a fresh, generation-guarded read.
- Metadata:
SnapshotMetadatarecords the depth, daemon generation, UTC start and end readings, and monotonicElapsedtime. UTC can move backwards if the clock is adjusted; useElapsedfor duration. - Not atomic: a snapshot spans several tmux commands. Contradictory parent,
child-count or active-child observations fail with
InconsistentSnapshotExceptionand emit no graph. Equal-count changes can escape detection. The command never retries. - Uncaptured data: uncaptured relations report
IsCaptured = falseand throw when enumerated. A field that was not captured raisesIncompleteSnapshotException; a captured empty string or null keeps its value. Property access never reads tmux. - After the daemon exits: captured panes expose
CurrentCommandandCurrentPath, and formatting andGet-Memberkeep working. They do not refresh objects.
Navigate a captured graph
- Parents: captured children keep their root through
Server, and parent properties return the captured instances when that depth is available. - Placement: a pane’s
Windowkeeps its session and index placement, including repeated links to the same window.Window.LinkedSessionslists each related session once. - Active children:
Session.ActiveWindow,Session.ActivePaneandWindow.ActivePanereturnCapturedValue<T>. CheckIsCaptured, then readValue. Reading an unavailableValueraisesIncompleteSnapshotException;OrNull()returns null instead. Active properties use the IDs from their own parent’s row, so separate reads can record different selections. - Filtering: filtering a collection changes only which items are selected. Traversing their parents still reaches the complete captured children.
- Refresh:
Update-TmuxPanerefreshes one pane’s fields. Its parent navigation does not borrow data from an older graph. Take another snapshot for a new graph.
Default tables show native identifiers, captured names or titles, and owner context. A handle resolved only by identifier shows blank columns for fields it has not captured, and the views tell that apart from other failures.
Errors
A read failure writes an error for the affected owner, including an endpoint
with no running server, and later owners in the pipeline continue. Use
-ErrorAction Stop to terminate instead.
Error IDs are Tmux.ConnectFailed,
Tmux.SnapshotFailed,
Tmux.SessionReadFailed,
Tmux.WindowReadFailed and
Tmux.PaneReadFailed. The error record keeps the core
exception and its dispatch metadata when it has them. Cancelling the pipeline
cancels the pending core operation, and borrowed server handles do not own the
daemon’s lifetime.