120 lines · 2.6 KB · executable
#!/usr/bin/env bash
set -euo pipefail

# Capture visible or scrolling content from a tmux pane.
#
# Usage:
#   tmux_capture.sh [options] [target]
#
# Target formats (default: active pane of current session):
#   session-name             → active pane in that session
#   session-name:window      → active pane in that window
#   session-name:window.pane → specific pane
#   :window.pane             → current session, specific pane
#   .pane                    → current session+window, specific pane
#
# Options:
#   -l, --lines N    Number of lines to capture from scrollback (default: visible only)
#   -a, --all        Capture entire scrollback history
#   -s, --strip      Strip trailing whitespace from each line
#   -j, --join       Join wrapped lines (unwrap)
#   -p, --prefix     Prefix each line with line number
#   -h, --help       Show this help

usage() {
	sed -n '4,/^$/p' "$0" | sed 's/^# \?//' >&2
	exit 1
}

LINES=""
ALL=false
STRIP=false
JOIN=false
PREFIX=false

while [[ $# -gt 0 ]]; do
	case "$1" in
	-l | --lines)
		LINES="$2"
		shift 2
		;;