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

Feature Request: Copy to Clipboard Option #2776

Closed
ysxninja opened this issue Nov 17, 2023 · 2 comments
Closed

Feature Request: Copy to Clipboard Option #2776

ysxninja opened this issue Nov 17, 2023 · 2 comments
Labels
feature-request New feature or request

Comments

@ysxninja
Copy link

ysxninja commented Nov 17, 2023

I would like to propose the addition of a --clip or similar option to the bat utility. This feature would allow users to copy the contents of a file directly to the clipboard, eliminating the need for a separate command-line utility like xclip or xsel.

Use Case And current workarounds

This feature would be particularly beneficial in copying text from files where users frequently need to copy file contents quickly.
Current alternatives are piping to xclip or xsel, or using a text editor like vim to open and copy contents of a file manually.

Additionally, if implemented, a way to Select Specific Parts of the File:

It would be valuable to have the ability to selectively copy parts of the file, similar to the functionality provided by commands like head or tail. For instance, being able to copy the first 10 lines (head 10) or a specific range of lines would enhance the flexibility of this feature.

@ysxninja ysxninja added the feature-request New feature or request label Nov 17, 2023
@eth-p
Copy link
Collaborator

eth-p commented Feb 8, 2024

I feel your pain with copying files, but I'm not sure if this would be within the scope of bat. The cat command is used for printing the contents of one or more files, and bat is follows suit as a syntax-highlighting printer for various file formats. Copying text directly from files feels like it would be better suited to a dedicated command, both for maintainability and compatability reasons.

If you don't mind using shell aliases, I might have something that works better for you:

alias pbcopy="xclip -selection clipboard -in"
alias pbpaste="xclip -selection clipboard -out"

MacOS uses pbcopy and pbpaste, which are simple commands that use standard input and standard output to copy/paste from the clipboard. The above aliases work similarly, and it makes copying as painless as:

pbcopy < some_file.txt
head -n20 some_file.txt | pbcopy
pbpaste | bat -l txt

@sharkdp sharkdp closed this as completed Feb 8, 2024
@eth-p
Copy link
Collaborator

eth-p commented Feb 12, 2024

I know the issue is closed, but I'm dropping a comment to reference #296 since it's related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants