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

Execute Arbitrary Command Via Keybinding #418

Open
fdncred opened this issue Jul 23, 2020 · 5 comments
Open

Execute Arbitrary Command Via Keybinding #418

fdncred opened this issue Jul 23, 2020 · 5 comments

Comments

@fdncred
Copy link

fdncred commented Jul 23, 2020

Since we have introduced keybindings in nushell we're getting some interest in using fzf since skim doesn't work on Windows. Along with that comes the ability to execute any arbitrary program via those configured keybindings. Is it possible to 'shell out' and execute a command that is defined in a keybinding today? I can't find it if it is. If it isn't can you point me to the location where this could be inserted via PR?

To be clear, this is really a two-pronged question.

  1. we'd like to be able to use fzf somehow in mac/*nix/windows
  2. we'd like to be able to run an executable via a keybinding.

Thanks.

@gwenn
Copy link
Collaborator

gwenn commented Jul 24, 2020

Do you know a library (in any language) that already supports theses features ?

  1. we'd like to be able to use fzf somehow in mac/*nix/windows

Could you please confirm that you want something like this:
#302

Maybe we should enhance the Completer trait and let implementations do their own complete_line logic.

https://github.com/kkawakam/rustyline/blob/master/src/completion.rs#L52

pub trait Completer {
...
    fn complete_line(&self
    someContext: SomeContext, // to be defined
    config: &Config,
) -> Result<Option<Cmd>> {
      // current default behaviour (redefined by nushell)
    }
}

So rustyline let nushell customize the display of candidates and user interaction.
But during the call to complete_line:

  • terminal should be kept in raw mode (or at least rollbacked to raw mode before complete_line returns),
  • rustyline will not be able to keep the screen coherent (rustyline repaints only its own lines).
  1. we'd like to be able to run an executable via a keybinding.

Could you please confirm that you want something like this:
#342
which may not interact well with the undo manager...

@sophiajt
Copy link

@gwenn - I'm coming up to speed on the current threads, but these are my early thoughts:

for #302 - I think what we want is more than just tabbing, but it's a start. Part of the problem here is that rustyline supports skim, but skim doesn't support Windows. We've been holding off adding support in nushell until the Windows support is available. Being able to do our own completions does have some advantages, so we could optionally call out into an external command like fzf.

Right, there'd need to be some contract between rustyline and the code handling the completion that things come back in a state that rustyline can handle.

For #342 - I think the request here is more around binding a keyboard shortcut to a special function, which for nushell would call into nushell to do something. From there, I'm guessing it would just return a string. Undo from that point would undo the string. I don't think we're asking for arbitarily complex edit commands, rather a way to call into things like the fzf mentioned above. Once it returns the string, we can give that back to rustyline and go from there.

@fdncred
Copy link
Author

fdncred commented Jul 24, 2020

Thanks for responding @gwenn

Do you know a library (in any language) that already supports theses features ?

At the bottom of [this page] (https://github.com/junegunn/fzf/wiki/Windows#powershell-support)is some windows implementations however, I wouldn't call any of them libraries. They're more of a wrapper around fzf.

Actually, if you peruse this page, all implementations mac/*nix/win seem to be wrappers around the executable versus libraries.

@jonathandturner answered the other questions nicely, so I'll leave those mostly alone and say, yes, #302 and #342 sound interesting but #342 where it's more inline with this comment and #306.

@DanielRivasMD
Copy link

What is the current status on this?

@rosshadden
Copy link

As a lover of fzf, I don't think any external tools like that should be coupled with the shell. If we could map arbitrary params, we could implement integrations like this ourselves in user-land.

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

No branches or pull requests

5 participants