cantino / mcfly

Fly through your shell history. Great Scott!
MIT License
6.77k stars 176 forks source link

Feature request: Key-binding to copy highlighted command to system clipboard #226

Open arijit-hal opened 2 years ago

arijit-hal commented 2 years ago

Hi, Is there a way to add a keybinding to copy a highlighted command from mcfly's heads-up display directly to the system clipboard? Presently, the only way I can achieve this consistently across several terminal emulators (kitty, gnome-terminal etc.) is by using the edit option (pressing TAB) and then copying the result into the emulator's internal buffer (using Ctrl+U). Thanks!

cantino commented 2 years ago

That's a nice feature idea, thanks @arijit-hal

navazjm commented 2 years ago

I would like to claim this one and try to figure it out.

What is the preferred end of action for this command? For example, after the user press the keybinding to copy the selected text, should the user stay in McFly or exit out?

arijit-hal commented 2 years ago

Ah nice follow up question! It would probably be preferable to stay within McFly after the selected content has been copied to the clipboard. This way once the user has pasted the copied content into their desired application, they can initiate another search and repeat the process if needed.

cantino commented 2 years ago

That makes sense.

navazjm commented 2 years ago

That's what I was thinking. On top of that, say the user copies the wrong command. It would be annoying to restart the application and then find the desired command again. I know I would find that annoying.

navazjm commented 2 years ago

For the keybindings, I am thinking of using 'yy' if the user is using vim mode, since in vim that will copy the whole line. I am not an emacs user but an article I read says to use Ctrl+k to copy a line. However, Ctrl+k already has a keybinding. Any recommendations for keybindings for emacs? Or any keybinding recommendations to keep it the same for both emacs and vim?

arijit-hal commented 2 years ago

I agree with the choice of 'yy' in vim mode. In the "usual" bash-like mode Ctrl+k should have been a good choice as it is the default for cutting a typed command in the bash shell from cursor till the end. If that does not work, I suggest Ctrl+i kind of hybrid between vim and Ctrl+k and short for "insert" into clipboard buffer or Ctrl+y if that can be used while inside McFly. Alternatively, setting custom keybindings through environment variables could also be another option.

navazjm commented 2 years ago

@cantino after doing some research, there is no clear way on copying text to clipboard using Rust's std lib. However, there is a crate that implements this functionality. How would you feel about using it?

Repo link: https://github.com/aweinstock314/rust-clipboard

arijit-hal commented 2 years ago

Seems like a reasonable crate. But, given the lack of sufficient knowledge about rust-crates I would like to get @cantino 's opinion.

cantino commented 2 years ago

Given its use in Mozilla Servo, I'm comfortable adding it.