Skip to content
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

feat: new "content" option to copy command #2447

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

Conversation

Dantescur
Copy link

Added the content type handling in the copy command, allowing file content to be copied to the clipboard.

This change extends the copy command by introducing a new "content"
option. When users use cg "content", the command reads the file's
contents and copies them to the clipboard instead of just copying file
paths or names.
@sxyazi
Copy link
Owner

sxyazi commented Mar 6, 2025

Thank you for the PR, I have some questions:

  • What is the behavior when the user selects multiple files?
  • What happens when the user copies a binary file, or a file contains binary content?
  • What happens when the user selects a text file along with a binary file?

@Dantescur
Copy link
Author

Dantescur commented Mar 6, 2025

  • What is the behavior when the user selects multiple files?

When multiple files are selected, the command works as expected, copying the contents of all the files, with a new line between each file's content.

Screenshot_06-Mar_02-35-42_8688

  • What happens when the user copies a binary file, or a file contains binary content?

When copying a binary file or a file containing binary content, the copy command attempts to read the file as text using fs::read_to_string. If the content cannot be interpreted as text (e.g., for binary files), an error will be caught and logged.

Screenshot_06-Mar_02-37-09_10992

In this case, the command will return an empty string (Cow::Borrowed(OsStr::new(""))) as a fallback to ensure the operation doesn't break.

  • What happens when the user selects a text file along with a binary file?

When both a text file and a binary file are selected, the copy command will first read the text file and copy its content to the clipboard. For the binary file, it will return an empty string, as binary content cannot be copied as text. The text content will be copied to the clipboard, while the binary file will be effectively ignored (in terms of content). The error from the binary file read attempt will also be logged as shown earlier.

I hope this helps clarify things! I'm open to any suggestions and appreciate all the feedback. Thanks for this great project ❤️

@Dantescur
Copy link
Author

@sxyazi Just following up on this PR—let me know if there's anything that needs improvement! I'm not very familiar with the codebase, so if you have any suggestions or a preferred approach, I'd be happy to adjust the implementation. Thanks for your time!

@sxyazi sxyazi force-pushed the main branch 2 times, most recently from 75fad25 to 9565c1b Compare April 4, 2025 23:42
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.

2 participants