Skip to content

feat: Add /copyprompt command to copy prompts without formatting #5558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

sinanptm
Copy link

@sinanptm sinanptm commented Aug 5, 2025

TLDR

This pull request introduces a new /copyprompt command to address the issue of copying prompts with unwanted terminal formatting. This command allows users to easily copy the last sent prompt to their clipboard as raw text, without any styling or indentation.

Dive Deeper

Previously, when a user tried to copy a prompt from the terminal, it would include formatting that made it difficult to reuse the prompt. To solve this, I have implemented a new /copyprompt command that specifically extracts the raw text of the last user-sent prompt and copies it to the clipboard. This ensures that the user gets a clean, usable version of the prompt without any manual cleanup.

If this /copyprompt command is deemed necessary, I will update the documentation to include details on its usage.

Reviewer Test Plan

To test this change, please follow these steps:

  1. Run the Gemini CLI and send a prompt.
  2. Run the /copyprompt command.
  3. Paste the content of the clipboard into a text editor to verify that the prompt is copied without any terminal formatting.

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker
Podman - -
Seatbelt - -

Linked issues / bugs

Resolves #5556

sinanptm and others added 2 commits August 5, 2025 09:06
This commit introduces a new `/copyprompt` command that allows users to copy the last sent prompt to the clipboard without any terminal formatting.

This addresses the issue where copying a prompt directly from the terminal would include unwanted styling and indentation, making it difficult to reuse the prompt.

Resolves: google-gemini#5557
@sinanptm sinanptm requested a review from a team as a code owner August 5, 2025 03:39
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @sinanptm, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the CLI's usability by adding a new /copyprompt command. This command provides a streamlined way for users to retrieve and copy their previous prompts without any formatting issues, improving the overall user experience. The changes include the command's core logic, its registration within the application, and a comprehensive suite of unit tests to ensure its reliability.

Highlights

  • New Feature: /copyprompt Command: I've introduced a new /copyprompt command that allows users to copy their last sent prompt to the clipboard as raw text, addressing issues with unwanted terminal formatting when copying directly.
  • Command Integration: The new /copyprompt command has been integrated into the CLI's built-in command loader, making it available for immediate use by users.
  • Comprehensive Testing: I've added a dedicated test file for the /copyprompt command, covering various scenarios including handling empty history, extracting text from multi-part messages, filtering non-text content, and robust error handling for clipboard operations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new /copyprompt command to copy prompts without formatting. There's a potential runtime error if lastUserMessage.parts is null or undefined, which can be prevented by using the nullish coalescing operator to provide an empty array as a fallback.

sinanptm and others added 4 commits August 5, 2025 09:12
This commit addresses a potential runtime error in the `/copyprompt` command that could occur if `lastUserMessage.parts` is null or undefined.

By using the nullish coalescing operator (`??`), we now provide an empty array as a fallback, preventing the application from crashing and ensuring the command is more robust.
@sinanptm
Copy link
Author

sinanptm commented Aug 9, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a /copyprompt command to copy the last user prompt. The implementation is well-tested and covers various edge cases. I've identified a performance issue in how the last user message is retrieved from the chat history, which could be impactful for long conversations. My suggestion provides a more efficient way to do this by iterating backwards through the history, improving performance by reducing memory allocation.

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.

Bug: Copying a prompt also copies terminal formatting
1 participant