Core Library0.xGuides

Choose documentation 2

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.

MoreLess about this notice

Capture, refresh and raw commands

Needs libtmux for PowerShell 0.x Install

The pane cmdlets accept a pane directly or from the pipeline and borrow its daemon. The examples assume $pane and $server are the pane and server selected as in Read tmux objects; none picks a global active server.

Capture text

Return one string per captured screen line:

Terminal window
$pane | Get-TmuxPaneContent

Capture the retained history as one string, joining wrapped screen lines:

Terminal window
$pane | Get-TmuxPaneContent -History -JoinWrappedLines -Raw

Capture an inclusive range, from ten lines before the visible screen through its fifth line. Zero is the top visible line and negative values address scrollback. Omitted bounds use the visible screen.

Terminal window
$pane | Get-TmuxPaneContent -StartLine -10 -EndLine 4
  • -History selects the oldest retained history. It combines with -EndLine but not -StartLine.
  • -Raw emits one string per pane, joining lines with LF and adding no trailing newline. Internal empty lines stay. An empty capture emits nothing, or one empty string with -Raw.

The result is rendered terminal text, not the process’s original output or a byte-exact stream. Sending input or receiving a pane-output event does not mean a command finished. Wait for a completion signal from the application, such as a cooperative wait channel, or use Invoke-TmuxPaneCommand, before relying on its output.

SwitchEffect
JoinWrappedLinesJoin lines that wrapped on screen; tmux applies this in place of trailing-space handling.
EscapeSequencesInclude terminal escape sequences representing captured attributes.
EscapeNonPrintableRepresent nonprintable bytes with octal escapes.
PreserveTrailingSpacesRetain trailing spaces.
TrimTrailingSpacesRequest tmux’s trailing-space trimming behavior.
AlternateScreenCapture the alternate screen.
QuietReturn empty content when an alternate screen is absent; other failures remain errors.
ModeScreenCapture a mode screen, such as copy mode.
PendingCapture an incomplete pending escape sequence.
HyperlinksInclude supported hyperlink capture metadata.
LineNumbersInclude supported line-number metadata.
LineFlagsInclude supported line-flag metadata.

-PreserveTrailingSpaces and -TrimTrailingSpaces together fail with Tmux.InvalidCapture before dispatch. Some switches depend on the tmux version and the core connection’s configuration.

Refresh captured metadata

Retain the replacement returned by an explicit refresh:

Terminal window
$currentPane = $pane | Update-TmuxPane

The original $pane keeps its captured values. Refresh reads tmux and returns another LibTmux.Pane; it changes no terminal state and takes no ownership of the daemon. Refreshing a pane in a repeatedly linked window is subject to the core’s contextual-target limits.

Run literal tmux arguments

Pass each argument as a separate array element. Nothing joins them into a shell command or expands their contents.

Terminal window
$server | Invoke-TmuxCommand -Arguments @(
'list-sessions', '-F', '#{session_name}'
)

The same literal arguments reach features without a cmdlet. This creates a named paste buffer, reads it and removes only that buffer. Deleting a buffer by name needs tmux 3.4 or newer, because earlier releases act on another buffer when the name is missing; Invoke-TmuxCommand refuses it there:

Terminal window
& {
$name = 'libtmux-' + [guid]::NewGuid().ToString('N')
$quiet = @{ Confirm = $false; ErrorAction = 'Stop' }
$created = $false
try {
$set = @('set-buffer', '-b', $name, 'hello from PowerShell')
$null = $server | Invoke-TmuxCommand -Arguments $set @quiet
$created = $true
$show = @('show-buffer', '-b', $name)
$shown = $server | Invoke-TmuxCommand -Arguments $show @quiet
$shown.StandardOutputLines
} finally {
if ($created) {
$delete = @('delete-buffer', '-b', $name)
$server | Invoke-TmuxCommand -Arguments $delete @quiet | Out-Null
}
}
}

This returns hello from PowerShell. StandardOutput keeps the bytes when lines do not fit.

For copy mode, send raw copy-mode and send-keys -X commands with an explicit pane ID, and read the screen with Get-TmuxPaneContent -ModeScreen. Copy mode changes the pane’s mode, so leave it with send-keys -X cancel.

  • Arguments: empty non-command arguments are kept. The first must name a command or alias; an empty, whitespace or leading-option first argument fails with Tmux.InvalidCommand before confirmation or dispatch.
  • Socket: select it on the server handle. Global options such as -S, -L and -f cannot replace the command name.
  • Pipeline: input must be a LibTmux.Server; an object with similar property names does not bind.
  • Confirmation: raw commands can mutate tmux or run shell work, so they always support -WhatIf and -Confirm, even for reads. Confirmation comes before discovery and dispatch, and shows the endpoint and command name but not the arguments.
Terminal window
$server | Invoke-TmuxCommand -Arguments @('kill-session', '-t', '$3') -WhatIf

Results and errors

Esc
Search in

Type to search.

Reference previewOpen reference