This hacky one-liner turns your fzf into a live REPL. There is not much to explain, see it for yourself. Please note that I will be adding more examples as I come up with them. You are also welcome to contribute them yourself by creating an issue or a pull request.
See also: fzf-launch - open any file directly from command line with a command of your choice
By abusing the --preview
flag of fzf
. It allows an arbitrary command to be executed as the query changes. The {q}
is then being substituted by your typed query. After exiting fzf
by pressing enter
, the --print-query
flag ensures that the typed
query will be printed to stdout.
Always be careful what you set the --preview
flag to! Imagine setting rm -rf
and then typing *
as the query
string!. I take no responsibility if you break anything!
ONLY USE THIS FOR COMMANDS WHICH ARE READ-ONLY!
ALWAYS KNOW WHAT YOU'RE TYPING/PASTING!
$ echo '' | fzf --print-query --preview 'echo "a\nb\nc\nd" | awk {q}'
$ echo '' | fzf --preview 'ls {q}'
$ echo '' | fzf --print-query --preview 'ruby -e {q}'
$ echo '' | fzf --preview 'man {q}'
$ echo '' | fzf --print-query --preview 'python -c {q}'