From f6ef0cf0409a7d611023478ea023591fb6dd69a8 Mon Sep 17 00:00:00 2001 From: Morgan Joyce Date: Thu, 4 Dec 2025 13:40:37 -0600 Subject: [PATCH] fix(tmux): respect visible pane when copying history --- .bash_aliases.d/tmux.sh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.bash_aliases.d/tmux.sh b/.bash_aliases.d/tmux.sh index dfad6112..4d756da5 100644 --- a/.bash_aliases.d/tmux.sh +++ b/.bash_aliases.d/tmux.sh @@ -10,5 +10,20 @@ alias tmux-branch='git checkout - && tmux source-file ~/.tmux.conf && echo "Swit # Quick access to tmux cheatsheet alias tmux-help="less ~/dotfiles/tmux-cheatsheet.md" -# Copy full tmux pane history (joined lines) to system clipboard -alias tmux-copy-history='tmux capture-pane -p -J -S -999999 | clipboard_copy' +# Copy visible history from the active (or last) pane to the system clipboard +tmux_copy_history() { + local target_pane + + if [ -n "$TMUX" ]; then + target_pane="$(tmux display-message -p '#{pane_id}')" + else + if ! target_pane="$(tmux display-message -p -F '#{pane_id}' -t '{last}' 2>/dev/null)"; then + echo "tmux-copy-history: no tmux session found" >&2 + return 1 + fi + fi + + # -S -0 captures from the top of the visible pane (respects a recent clear) + tmux capture-pane -p -J -S -0 -t "${target_pane}" | clipboard_copy +} +alias tmux-copy-history='tmux_copy_history'