by phforms · 3y ago · 0 comments
fuzz() {
file=$(fzf)
if [ ${#file} -gt 0 ]; then
nvim "$file" # or any editor you prefer
else
:
fi
} vim $(fzf)
but don't press enter. Press tab instead. The shell will expand the $(), which will run fzf and let you choose a file. When you've made your choice, fzf will exit, and your choice will be written in place of the $(), so you can see the result before you run it. It works with any command, not just vim. It's particularly useful when doing multi-selects. And if you press ESC then nothing gets written.I've only tested this with zsh, not sure how other shells behave. And you may need to alter fzf's default command or pipe something into it.
I just love how simple it is to stick anything together via the universal plain text interface in the shell and even pipe this text/dataflow through interactive tools like fzf, as you just mentioned.
fuzz() { file=$(fzf) && nvim "$file"; }