tmux capture-pane
Capture the contents of a pane.
Common uses¶
Run these commands inside tmux, in the pane you want to capture. TMUX_PANE identifies that pane.
Print the visible pane
tmux capture-pane -p -t "$TMUX_PANE"Include up to 1,000 history lines and join wrapped lines
tmux capture-pane -p -J -S -1000 -t "$TMUX_PANE"Syntax¶
tmux capture-pane [-aCeFHJLMNpPqT] [-b buffer-name] [-E end-line] [-S start-line] [-t target-pane]Alias: capturep.
Options¶
Output and line range¶
-p- Print to standard output. Without this flag, tmux saves the capture in a paste buffer.
-b name- Choose the paste buffer when -p is omitted. Without -b, tmux creates a new buffer.
-t pane- Choose the pane to capture. Inside tmux, "$TMUX_PANE" identifies the current pane.
-S start- First line to capture. Zero is the first visible line; negative numbers reach into history. Use - for the start of history.
-E end- Last line to capture. Use a line number, or - for the end of the visible pane. By default, capture only the visible pane.
Text formatting¶
-J- Join wrapped lines and preserve trailing spaces. Implies -T.
-e- Keep escape sequences for text attributes and colors.
-C- Escape non-printable characters as octal \xxx sequences.
-N- Preserve trailing spaces at the end of each line.
-T- Ignore trailing positions that contain no character.
-H- Capture only hyperlink targets, separated by spaces when a line contains several.
-L- Prefix each line with its line number.
-F- Prefix each line with its flags: - none, D unused, O output, P prompt, X extended cells, H hyperlinks.
Screens and pending output¶
-a- Capture the alternate screen instead of the normal screen. History is unavailable. Fails if no alternate screen exists.
-q- With -a, suppress the error when no alternate screen exists.
-M- Capture the mode screen, such as copy mode, when the pane is in a mode.
-P- Capture a received but incomplete escape sequence, rather than the pane contents.
Original manual wording
-p is given, the
output goes to stdout, otherwise to the buffer specified with
-b or a new buffer if omitted. If
-a is given, the alternate screen is used, and the
history is not accessible. If no alternate screen exists, an error will be
returned unless -q is given. Similarly, if the
pane is in a mode, -M uses the screen for the
mode. If -e is given, the output includes escape
sequences for text and background attributes. -C
also escapes non-printable characters as octal \xxx.
-T ignores trailing positions that do not contain
a character. -N preserves trailing spaces at each
line's end and -J preserves trailing spaces and
joins any wrapped lines; -J implies
-T. -P captures only any
output that the pane has received that is the beginning of an as-yet
incomplete escape sequence. -L includes the line
number at the start of each line and -F includes
the flags (where ‘-’ is no flags,
‘D’ is an unused line,
‘O’ is a line marked as output,
‘P’ is a line marked as a prompt,
‘X’ is a line containing extended
cells and ‘H’ is a line with
hyperlinks). With -H, only hyperlinks in the
specified lines are captured. Multiple hyperlinks on the same line are
separated by spaces.
-S and -E
specify the starting and ending line numbers, zero is the first line of
the visible pane and negative numbers are lines in the history.
‘-’ to -S
is the start of the history and to -E the end of
the visible pane. The default is to capture only the visible contents of
the pane.
Guides¶
C implementation¶
Internal declarations in tmux 3.7c:
Use from a library¶
Each API describes its own defaults, errors and execution model.
tmux sources and license
Syntax comes from tmux 3.7c list-commands. See the global options for sockets and configuration, and command syntax and targets.
Behavior is taken from the tmux 3.7c manual.
Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.