Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions .bash_aliases.d/tmux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}')"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback case for when not inside tmux may fail if no tmux session exists. The tmux display-message command will error if there's no tmux server running, causing the function to fail silently or with an error message.

Suggested change
target_pane="$(tmux display-message -p -F '#{pane_id}' -t '{last}')"
target_pane="$(tmux display-message -p -F '#{pane_id}' -t '{last}' 2>/dev/null)" || { echo "No tmux session found" >&2; return 1; }

fi

tmux capture-pane -p -J -S -999999 -t "${target_pane}" | clipboard_copy
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function should validate that target_pane is not empty before attempting to capture the pane. If pane detection fails, this will pass an empty string to the -t option, which may cause unexpected behavior.

Suggested change
tmux capture-pane -p -J -S -999999 -t "${target_pane}" | clipboard_copy
if [ -z "$target_pane" ]; then
echo "Failed to determine target pane" >&2
return 1
fi
tmux capture-pane -p -J -S -999999 -t "${target_pane}" | clipboard_copy

}
alias tmux-copy-history='tmux_copy_history'