junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
64.3k stars 2.38k forks source link

[Feature Request] Combining `--expect` and `--bind` #3810

Closed ibhagwan closed 4 months ago

ibhagwan commented 4 months ago

Hi again @junegunn 👋

When scripting fzf, it is sometimes desirable to perform different actions upon completion depending on the key pressed, for example, in fzf-lua users use enter to open the file and ctrl-q to send the selection to quickfix list.

Now say that instead of sending the selection to quick fix we want to send all results to quickfix, we can do that with --bind=ctrl-q:select-all+accept but the output doesn’t print the pressed keybind, for that we need to add --expect:ctrl-q, however combining both we lose the --bind as expect takes over:

The below works but the select-all+accept action is ignored

fzf --expect=ctrl-q --bind=ctrl-q:select-all+accept
junegunn commented 4 months ago

I see. --expect was added before --bind was even a thing, so its implementation currently does not consider bound actions on the same key, but it really should.

A few more thoughts:

ibhagwan commented 4 months ago

Got it @junegunn.

I like your ideas as they give maximum flexibility, I also thought about a simpler solution, perhaps something like --print-accept-key which adds the accept key to the output similarly to --print-query?

junegunn commented 4 months ago

Yeah, I also considered that approach, but I think consolidating the features around the event binding mechanism is the way to go.

6b4358f will make --expect compatible with --bind. Also, I'll also be adding print(...) action.

ibhagwan commented 4 months ago

Ty @junegunn!

Can confirm this works on the latest devel commit 0.52.1 (6b4358f6).