From a99831896771caaf8468e2e6ca0fa1bb970e7787 Mon Sep 17 00:00:00 2001 From: Morgan Joyce Date: Thu, 4 Dec 2025 13:35:35 -0600 Subject: [PATCH] fix(tmux): target current pane for history copy --- .bash_aliases.d/tmux.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.bash_aliases.d/tmux.sh b/.bash_aliases.d/tmux.sh index dfad6112..238999ec 100644 --- a/.bash_aliases.d/tmux.sh +++ b/.bash_aliases.d/tmux.sh @@ -10,5 +10,17 @@ 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 full history from the current (or last) pane to system clipboard +tmux_copy_history() { + local target_pane + + # If we're inside tmux, use the active pane; otherwise fall back to the last active pane + if [ -n "$TMUX" ]; then + target_pane="$(tmux display-message -p '#{pane_id}')" + else + target_pane="$(tmux display-message -p -F '#{pane_id}' -t '{last}')" + fi + + tmux capture-pane -p -J -S -999999 -t "${target_pane}" | clipboard_copy +} +alias tmux-copy-history='tmux_copy_history'