cantino / mcfly

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

Iss226 - Copy Highlighted Command to system clipboard #232

Closed navazjm closed 2 years ago

navazjm commented 2 years ago

Closes #226

As discussed in issue 226, I installed the rust-clipboard crate to easily add text to the system clipboard. I updated the menu interface text to display the new keybinding for the user to know which keys to press to copy the selected command. I decided to use 'Ctrl+y' in both emacs and vim keybindings. I could not use the default keybindings from either one, so I decided it would be best to use the same keybinding for both. Also, I decided that the user should be able to use the keybinding in both insert and command mode of vim.

Love to hear your feedback @cantino 🤘🏼

cantino commented 2 years ago

Thanks @michaelnavs, this is a cool feature! I just tested it and it worked on my Mac. A few thoughts:

navazjm commented 2 years ago
navazjm commented 2 years ago

Tested on Linux (Ubuntu), worked as expected. It behaves just like MacOS. Tested it on Windows with WSL Ubuntu and I run into an error on startup. Capture

The error comes from:

    pub fn new(settings: &'a Settings, history: &'a History) -> Interface<'a> {
        Interface {
            history,
            settings,
            input: CommandInput::from(settings.command.to_owned()),
            selection: 0,
            matches: Vec::new(),
            debug: settings.debug,
            run: false,
            delete_requests: Vec::new(),
            menu_mode: MenuMode::Normal,
            in_vim_insert_mode: true,
            clipboard_context: ClipboardProvider::new().unwrap(), // error here
        }
    }
cantino commented 2 years ago

Did that happen on boot, or only when you tried to copy?

navazjm commented 2 years ago

It happens on boot

cantino commented 2 years ago

I think we need to defer calling ClipboardProvider::new().unwrap() until the user actually tries to copy, that way the crash is limited to that UI interaction.