1

What would be an easy way to bind a key binding from fish to run the current command prompt and pipe it to fzf for easy search/selection?

i.e. a 1 key-press way of accomplishing | fzf (enter)?

1 Answer 1

1

Seems like a pretty straightforward bind function, if I'm understanding correctly. At its simplest:

Saved in ~/.config/fish/functions/__append_pipe_fzf.fish:

function __append_pipe_fzf
    set -l cmd (commandline -b)
    commandline -r $cmd" | fzf"
    commandline -f execute
end

And then bind it to a key with something like: bind -k nul __append_pipe_fzf nul binds to Ctrl+Space (or +Space on Mac, which I believe is your case).

Of course, you can make this more robust by checking to see if the current command ends with a process starting with | fzf and remove it if so. Right now, it could conceivably append the | fzf even when you already have one there. Also, if you pressed it when the current commandline ended in |, I think it would generate an "or" statement, instead of what you want.

2
  • 1
    Thanks! Minor note, I think the first commandline probably doesn't want the -o since multi-word commands will be split into multiple lines each appended with a | fzf.
    – Xster
    Commented Jan 19, 2021 at 17:04
  • 1
    Thanks! You're absolutely right. I'd offer to have you update the answer if it weren't for Stack's "6 character minimum" rule. So at least I can give you some upvote rep on the assist in the comment. Commented Jan 19, 2021 at 22:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .