Skip to content

pawelduda/fzf-live-repl

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

πŸš€ fzf-live-repl πŸš€

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.

Featured in my blog post

See also: fzf-launch - open any file directly from command line with a command of your choice

How?

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.

WARNING!

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!

Examples

Live awk preview

$ echo '' | fzf --print-query --preview 'echo "a\nb\nc\nd" | awk {q}'

live-awk-preview

Peek into contents of a directory

$ echo '' | fzf --preview 'ls {q}'

fzf-ls

Execute a Ruby script

$ echo '' | fzf --print-query --preview 'ruby -e {q}'

fzf-ruby

Instantly browse manpages (and find the relevant flag as you type the command - TODO)

$ echo '' | fzf --preview 'man {q}'

Execute a Python script

$ echo '' | fzf --print-query --preview 'python -c {q}'

About

Turn your fzf into a live REPL

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages