altsem / gitu

A TUI Git client inspired by Magit
MIT License
1.66k stars 87 forks source link

Copy commit hash to clipboard #119

Closed altsem closed 3 months ago

altsem commented 3 months ago

It'd be useful to be able to copy a commit hash. Select anything with a commit hash, press y and it would be copied to your clipboard.

y is already bound to show_refs in the current config, but I suggest moving show_refs to maybe Y.

FrancoRav commented 3 months ago

I am guessing this requires an external crate to access the clipboard, right? If so, arboard seems to be the most downloaded one, apart from a Windows-only crate.

altsem commented 3 months ago

Yea I think pulling in a dependency is the way to go here. Arboard seems fine!

FrancoRav commented 3 months ago

I have implemented it. One issue is that, for the X clipboard (not sure about wayland), the copied content is dropped when the program exits. That is how it works for most Linux apps though, so I guess it wouldn't be a problem (there is a workaround, if needed) I just have a couple of questions before I submit the PR.

  1. Should I move show_refs to Y and bind copy_hash to y, as suggested in the issue?
  2. I suppose there should be some visual indication that the hash was copied (a message or something). What should I do? Right now the only use of the log is commands and outputs, and as this Op doesn't use commands, it's not showing anything at the moment, and would require adding functionality to the ui module if I'm not mistaken.
altsem commented 3 months ago
  1. Yea I think this might be the way to go, open for ideas of course.
  2. Could add a new variant to this enum, like "Info" or similar. Should be pretty easy. It doesn't hurt if it is unnecessarily in the "command log" for now.

Could start somewhere and iterate! Happy to see this catching interest :)