Filter and query tmux objects
Needs libtmux for PowerShell 0.x Install
Use Where-Object to filter captured objects locally. Use structured criteria
when a selection needs reuse, serialization or an inspectable source plan. Both
return native tmux objects that feed other cmdlets.
Import LibTmux and select an existing endpoint as $server with
New-TmuxServer. The examples borrow it and
create or remove no sessions. Read the daemon version for source planning, then
capture its complete pane graph:
$captured = $server | Get-TmuxServer -ErrorAction Stop | Get-TmuxSnapshot -ErrorAction StopStart with PowerShell
Select panes at least 50 columns wide. Property access and filtering use the captured data and never contact tmux.
$captured.Panes | Where-Object { $_.Width -ge 50 -and $_.Height -gt 0 }For reuse, construct the same condition as a native QueryDocument:
$query = New-TmuxQuery -Target Pane -Criteria @{ Width = @{ Ge = 50 } Height = @{ Gt = 0 }}Apply it to the captured panes. Input order, duplicates and object identity stay intact, and parent and child relations keep the complete graph.
$captured.Panes | Select-TmuxPane -Query $queryCriteria vocabulary
Get-TmuxQueryField returns native catalog descriptors. Inspect the numeric
width field and its supported wire operations:
Get-TmuxQueryField -Target Pane | Where-Object WireName -CEQ 'pane_width'- Criteria accept a field’s catalog wire name or its native property path:
Widthandpane_widthname the same field. - Field and operator keys ignore case. Giving both aliases in one map is an error.
- A bare value means equality, and the entries of a map combine with
And.
The catalog’s Operators use JSON wire names. In criteria maps use these
PowerShell keys; an unsupported field and operator pair fails at construction.
| Criteria key | Native wire operation | Value |
|---|---|---|
Bare value or Eq; Ne¶ | equal; notEqual | Native scalar value |
Lt, Le, Gt, Ge¶ | lessThan, lessThanOrEqual, greaterThan, greaterThanOrEqual | Int64-representable integer |
StartsWith, EndsWith, Contains¶ | startsWithOrdinal, endsWithOrdinal, containsOrdinal | String |
EqualIgnoreCase¶ | stringEqualOrdinalIgnoreCase | String |
StartsWithIgnoreCase, EndsWithIgnoreCase, ContainsIgnoreCase¶ | startsWithOrdinalIgnoreCase, endsWithOrdinalIgnoreCase, containsOrdinalIgnoreCase | String |
In, NotIn¶ | or of equal, optionally not | Array or list of scalar values |
IsNull, IsNotNull¶ | equal or notEqual with null | $true only |
Regex¶ | regex | Map with Pattern and optional Options list |
Some, Every, None¶ | any, all, or negated any | Child criteria for a collection relation |
Is, IsNot¶ | related, optionally negated | Child criteria for a to-one relation |
And, Or, Not¶ | and, or, not | Criteria lists for And/Or; one criteria map for Not |
Strings
- Equality, membership and substring matching are ordinal and case-sensitive.
In PowerShell compare with
-ceqor-cin, not-eqor-in. EqualIgnoreCase,StartsWithIgnoreCase,EndsWithIgnoreCaseandContainsIgnoreCaseask for ordinal case-insensitive matching.- Nothing expands wildcards or normalizes strings.
- The catalog also lists
stringEqualOrdinal; in criteria that is bare string equality orEq.
Values
- Integers are not coerced from strings, Booleans, enums, floating-point or decimal values.
- IDs take the matching native ID type or a correctly prefixed string. Single-
quote session IDs such as
'$0'. $nullmeans explicit absence, and an omitted field is unconstrained. An empty string is a value.- ScriptBlocks belong in
Where-Object; they are not translated into criteria.
Collections
- A collection property has a scalar path and a relation path. Use
'Windows.Count'for a numeric comparison andWindowswithSome,EveryorNone. - A condition that needs both paths takes an explicit
Andwith separate maps. ActivePaneandActivePane.Valuename the same captured to-one relation.- An uncaptured relation raises an error; it never becomes empty data.
Limits
These construction limits count the nodes that membership and operator maps expand into:
| Limit | Maximum |
|---|---|
| Predicate depth¶ | 32 |
| Predicate node occurrences¶ | 512 |
| String length¶ | 4,096 Unicode scalar values |
| Regex pattern length¶ | 1,024 Unicode scalar values |
| Encoded JSON¶ | 262,144 UTF-8 bytes |
| Membership entries¶ | 128 |
Cycles, duplicate aliases, invalid Unicode and values past these limits are
rejected. A document owns its values, so editing the original hashtable or list
does not change a query. Serialization uses one schema, libtmux-query version
2, and the module includes its JSON schema file.
Match captured relationships
Select windows with at least one pane that meets both size conditions:
$captured.Windows | Select-TmuxWindow -Criteria @{ Panes = @{ Some = @{ Width = @{ Ge = 50 }; Height = @{ Gt = 0 } } }}- Both conditions apply to the same pane. Two separate
Someclauses may match different panes. - On an empty captured collection
Everyis true,Someis false andNoneis true. IsandIsNottraverse one captured related object.- Linked windows keep their session and index placement, so a pane ID can appear in several input placements. Selection does not deduplicate them.
Combine alternatives and exclusions to select API or log windows while excluding scratch windows:
$captured.Windows | Select-TmuxWindow -Criteria @{ Or = @(@{ Name = @{ StartsWith = 'api-' } }, @{ Name = 'logs' }) Not = @{ Name = @{ Contains = 'scratch' } }}For a regular expression, pass an explicit pattern and semantic option list:
$captured.Windows | Select-TmuxWindow -Criteria @{ Name = @{ Regex = @{ Pattern = '^API-'; Options = @('IgnoreCase') } }}Regex uses the .NET dialect, with
CultureInvariant always on. Options accept
IgnoreCase, Multiline,
ExplicitCapture,
Singleline,
IgnorePatternWhitespace and
CultureInvariant. Execution-only flags such as
Compiled are rejected, and a running match has a
one-second timeout. This is the .NET dialect, not a promise of regex
compatibility with other languages.
Store a query or acquire a fresh result
ConvertTo-TmuxQueryJson returns a JSON string suitable for storage. Restore
that string with New-TmuxQuery -Json; this round-trip does not read tmux:
New-TmuxQuery -Json ($query | ConvertTo-TmuxQueryJson)Prepare a plan using the daemon version from the earlier capture. Planning
and inspecting $queryPlan perform no I/O:
$queryPlan = $query | Get-TmuxQueryPlan -DaemonVersion $captured.DaemonVersionPushedPredicate, ResidualPredicate, RequiredFields,
RequiredSnapshotDepth and
FallbackReasons explain how it runs. A plan reads no data.
-Pushdown Autouses exact supported source evaluation.Neverevaluates locally.Requirerejects any local residual.
Execute it against the selected endpoint when a fresh result is needed:
$server | Invoke-TmuxQuery -Plan $queryPlan -AsResult -ErrorAction Stop-AsResultemits oneQueryResult, even with no matches. Its indexed rows refer to the completeSnapshot; filtering does not prune that graph. Without it, matching objects flow down the pipeline one by one.Invoke-TmuxQuery -Query $queryplans against a freshly observed daemon version instead.- Execution never starts an absent daemon, and a prepared plan must match the observed version.
- Acquisition is not an atomic transaction.
-NativeFilter with -Target is a separate expert escape hatch for raw tmux
format filtering. It cannot combine with -Query, -Plan, -Pushdown or
-AsResult, and its rows promise no complete structured-query snapshot.
Require exactly one match
Resolve the captured development session before handing it to another command:
$captured.Sessions | Select-TmuxSession -Criteria @{ Name = 'development' } -ExactlyOne-ExactlyOneholds the match until finite input completes.- Zero or several matches end with
Tmux.NoMatchorTmux.MultipleMatches. - Invalid inputs, unavailable relations, evaluation errors and a pipeline stop suppress the held object.
- An infinite stream cannot establish exact cardinality.
The guarantee covers the objects the selector received. A non-terminating error
upstream can skip a source and still leave one match, so use -ErrorAction Stop
on every upstream acquisition when you need complete input before a mutation. It
does not roll back changes another command already made. Local selection never
refreshes captured objects; acquire again to see changes.