Skip to content

fix: scope tmux history copy to visible pane#1435

Open
atxtechbro wants to merge 1 commit intomainfrom
tmux-copy-history-visible-only
Open

fix: scope tmux history copy to visible pane#1435
atxtechbro wants to merge 1 commit intomainfrom
tmux-copy-history-visible-only

Conversation

@atxtechbro
Copy link
Owner

Git Statistics

  • 1 file changed

Summary

  • adjust tmux-copy-history to use the active pane (or last active when run outside tmux)
  • limit capture to the visible pane contents (-S -0) so clearing the screen drops prior scrollback
  • keep clipboard piping via clipboard_copy for cross-platform support

Testing

  • tmux_copy_history (manual) inside tmux

@amazon-q-developer
Copy link
Contributor

Code review in progress. Analyzing for code quality issues and best practices. You can monitor the review status in the checks section at the bottom of this pull request. Detailed findings will be posted upon completion.

Using Amazon Q Developer for GitHub

Amazon Q Developer1 is an AI-powered assistant that integrates directly into your GitHub workflow, enhancing your development process with intelligent features for code development, review, and transformation.

Slash Commands

Command Description
/q <message> Chat with the agent to ask questions or request revisions
/q review Requests an Amazon Q powered code review
/q help Displays usage information

Features

Agentic Chat
Enables interactive conversation with Amazon Q to ask questions about the pull request or request specific revisions. Use /q <message> in comment threads or the review body to engage with the agent directly.

Code Review
Analyzes pull requests for code quality, potential issues, and security concerns. Provides feedback and suggested fixes. Automatically triggered on new or reopened PRs (can be disabled for AWS registered installations), or manually with /q review slash command in a comment.

Customization

You can create project-specific rules for Amazon Q Developer to follow:

  1. Create a .amazonq/rules folder in your project root.
  2. Add Markdown files in this folder to define rules (e.g., cdk-rules.md).
  3. Write detailed prompts in these files, such as coding standards or best practices.
  4. Amazon Q Developer will automatically use these rules when generating code or providing assistance.

Example rule:

All Amazon S3 buckets must have encryption enabled, enforce SSL, and block public access.
All Amazon DynamoDB Streams tables must have encryption enabled.
All Amazon SNS topics must have encryption enabled and enforce SSL.
All Amazon SNS queues must enforce SSL.

Feedback

To provide feedback on Amazon Q Developer, create an issue in the Amazon Q Developer public repository.

For more detailed information, visit the Amazon Q for GitHub documentation.

Footnotes

  1. Amazon Q Developer uses generative AI. You may need to verify generated code before using it in your environment. See the AWS Responsible AI Policy.

Copy link
Contributor

@amazon-q-developer amazon-q-developer bot left a comment

Choose a reason for hiding this comment

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

Review Summary

This PR improves the tmux history copy functionality by replacing a simple alias with a more sophisticated function that properly handles pane targeting and limits capture to visible content. The implementation is sound and addresses the stated goals.

Key Changes

  • ✅ Replaces global history capture with visible-only content using -S -0
  • ✅ Adds proper pane targeting (current pane inside tmux, last pane outside)
  • ✅ Includes error handling for missing tmux sessions

Issues Found

  • Shell Quoting: Three instances need proper quoting to prevent word splitting and pathname expansion

The changes are functionally correct and improve the user experience by scoping the copy operation to visible content while maintaining cross-platform clipboard support.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

local target_pane

if [ -n "$TMUX" ]; then
target_pane="$(tmux display-message -p '#{pane_id}')"
Copy link
Contributor

Choose a reason for hiding this comment

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

Quote the variable expansion to prevent word splitting and pathname expansion.

Suggested change
target_pane="$(tmux display-message -p '#{pane_id}')"
target_pane="$(tmux display-message -p "#{pane_id}")"

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Quote the variable expansion to prevent word splitting and pathname expansion.

Suggested change
if ! target_pane="$(tmux display-message -p -F '#{pane_id}' -t '{last}' 2>/dev/null)"; then
if ! target_pane="$(tmux display-message -p -F "#{pane_id}" -t "{last}" 2>/dev/null)"; then

# -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'
Copy link
Contributor

Choose a reason for hiding this comment

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

Quote the variable expansion to prevent word splitting and pathname expansion.

Suggested change
alias tmux-copy-history='tmux_copy_history'
alias tmux-copy-history="tmux_copy_history"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant