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)
?
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.
-o
since multi-word commands will be split into multiple lines each appended with a | fzf
.