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: copy selected process command to clipboard #496

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

stevenxxiu
Copy link
Contributor

@stevenxxiu stevenxxiu commented Jan 29, 2023

This is for [REQUEST] Include a method to copy process parameters · Issue #346 · aristocratos/btop.

Now when a process is selected, can press X to copy its command.

I'm not too sure what key to use here, so thought of X as in Ctrl + X for cut. Most keys seem to be used up.

I looked at macOS: Copy out the select process's command line by porceCodes · Pull Request #478 · aristocratos/btop for some inspiration. Incorporated some of the code, like extending the maximum command line length that's stored.

Took some of your comments into account:

Only tested on X11.

@stevenxxiu stevenxxiu force-pushed the feat/copy-cmd branch 2 times, most recently from c7c3557 to 113d510 Compare January 29, 2023 11:34
@stevenxxiu
Copy link
Contributor Author

Hmm I just realized that dacap/clip: Cross-platform C++ library to copy/paste clipboard content is X11 only. Is there some library perhaps that supports Wayland as well?

@stevenxxiu stevenxxiu force-pushed the feat/copy-cmd branch 4 times, most recently from 9156e4a to 6d43925 Compare January 29, 2023 13:21
@aristocratos
Copy link
Owner

@stevenxxiu @porceCodes
Before we get too deep down the rabbit hole of supporting the clipboards of every major windowing system 😉
There might be a much simpler solution;

A button called full cmd that shows the full command line for the selected process in a new box, pauses btop mouse control and pauses the background "drawing" so the text can be selected and copied manually. If it won't fit on one screen we can either split it in to multiple pages or switch back to "normal" terminal mode which can be scrolled and print it there and wait for "return to continue" or something like that.
This would also allow it to work in a TTY framebuffer with tmux, screen, etc.

And would avoid the mess of determining the current windowing system and adding external libraries on Linux.
The current code in #478 is also problematic because the Objective-C code used can only be compiled with clang, and even with clang 15 it's currently problematic to get btop to compile due to C++20 not fully being implemented, see #490.

What do you guys think of this solution? It would certainly simplify things a bit.

@stevenxxiu
Copy link
Contributor Author

stevenxxiu commented Jan 30, 2023

That would be good if copying can still be done with one key. But I'm not sure if terminal emulators support copying regions selected in other programs. I just tried selecting some region in the Micro text editor and using WezTerm's copying key, but that didn't copy anything. Turns out Micro uses some clipboard library itself.

One goal for mine here is to do it quickly and more easily than the pgrep mess.

If I have to manually drag my mouse to copy the text, that just becomes a pain.

@aristocratos
Copy link
Owner

@stevenxxiu
Not one key, because the terminal needs to do the "selecting", but using WezTerm and it's default keybinds as an example:

  1. x or whatever key used in btop to show the full command line.
  2. CTRL + SHIFT + X to enter copy mode. The cursor should be left on the first character in the text by btop.
  3. Select the region and CTRL + SHIFT + c to copy to clipboard.

My question here would be how many people have a need to regularly copy the command line of a running process, would just having the ability to see the full cmd be enough for most people and if need be manually select and copy it.

Is there enough people that would use this that it warrants a single key click and the extra includes and more involved compile process that comes with it?

If that is the case, another solution could be to add a config setting for copy command which is executed with the processes command line as argument (with dropped priviliges). It would be left empty by default but anyone that needs the functionality can manually add for example xclip as a copy command.

@stevenxxiu
Copy link
Contributor Author

@aristocratos

Well I think your idea of showing the full command line would be quite useful. Just to get a peek, whether it'll be copied not. I'm not sure how you would implement it, nor am I too fluent in C++ so it would be great if you made that happen 👍.

I think there are enough people who want to copy the command line, as there are already a few issues about it, and 2 PRs, including mine.

Using a copy command config setting seems quite ideal, as that'll support Wayland too. I'll give that a shot and code that. How do you envision dropping the privileges?

@stevenxxiu
Copy link
Contributor Author

I added a copy_command setting, and tested that it works, by setting it to:

copy_command = "/usr/bin/xclip -selection clipboard"

@stevenxxiu stevenxxiu force-pushed the feat/copy-cmd branch 2 times, most recently from 6a41af4 to 584647a Compare January 31, 2023 04:01
@porceCodes
Copy link

My question here would be how many people have a need to regularly copy the command line of a running process, would just having the ability to see the full cmd be enough for most people and if need be manually select and copy it.

I think being able to see the full command, however long it is, is more useful than being copying-out that text. By doing so, we can separate out pending concerns from a primary usefulness. Please note however, the maximum length for a command line characters can be large enough not to fit within a single screen, and may require scrolling when visual selection is required.

@stevenxxiu
Copy link
Contributor Author

If the command is so long you have to scroll to see it, it'll probably be hard to tell what's in it. This is another case where copying it becomes very useful, to look at it in a text editor.

…opy to clipboard instead, to support all windowing systems
@stevenxxiu
Copy link
Contributor Author

stevenxxiu commented Dec 27, 2023

Any chance of taking a look at this again?

I changed the default key to y, as in "yank" in Neovim. This feels a bit more natural vs x, like in Ctrl + x.

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.

3 participants