Have you ever pressed the up arrow 47 times looking for that one docker run command from last Tuesday? The one with all the flags? You pass it, panic, press down, overshoot, and end up running ls for the fourth time out of pure despair?
Friend. Put the arrow key down. Meet fzf.
fzf is a fuzzy finder. You give it a list of anything (files, commands, git branches, your hopes and dreams) and it gives you a search box that forgives typos. Type dkrrun and it finds docker run. It's like autocomplete that went to therapy and learned to be supportive.
Install it
sudo apt install fzf # Debian, Ubuntu
sudo dnf install fzf # Fedora
Now the important bit, the shell integration. That's where the magic keys come from. On a recent fzf (0.48 and later), add one line to your shell's config file:
# ~/.bashrc
eval "$(fzf --bash)"
# ~/.zshrc
source <(fzf --zsh)
Is your distro's fzf older? The same bindings ship as a script, usually under /usr/share/doc/fzf/examples/ on Debian and Ubuntu, and you source that instead. Open a new terminal and let's play.
Ctrl-R: your history, but searchable
Press Ctrl-R and your entire shell history appears in a list, with a search box at the bottom. Type a few letters of anything you remember: rsync bak, kubectl logs, that ssh thing. (Okay, maybe not that last one.) Arrow up or down to pick, press Enter, and the command lands on your prompt, ready to edit or run.
This one key is worth the whole install. Your up-arrow can finally retire.
Ctrl-T: paste a file path
Typing vim and can't remember where that config file lives? Press Ctrl-T, fuzzy-search every file under the current folder, hit Enter, and the path gets pasted right where your cursor is.
vim <Ctrl-T> → type "ngx conf" → vim ./deploy/nginx/site.conf
Press Tab on several files to pick more than one.
Alt-C: teleport into a folder
Alt-C lists every directory under you. Pick one and you're cd'd straight into it. It's basically teleportation, minus the risk of arriving with your molecules rearranged.
The ** trick
With the integration loaded, two stars and Tab open fzf right in the middle of a command:
cd **<Tab>
vim **<Tab>
ssh **<Tab> # hosts from your ssh config and known_hosts
kill -9 **<Tab> # pick a process from a list
That last one is great. No more ps aux | grep and copying the PID by hand like it's 1998.
Previews, because we're fancy
fzf can show a preview of whatever is highlighted:
fzf --preview 'head -50 {}'
{} is the highlighted line. If you have bat installed (it's in a review coming up soon, wink), swap in bat --color=always {} for syntax-highlighted previews and feel like a movie hacker.
Pipe anything into it
Here's the secret: fzf doesn't care what the list is. Anything that prints lines can feed it:
git branch | fzf | xargs git checkout
That's a fuzzy branch switcher in one line. Your Git branches are called fix-thing-2-final-REAL, aren't they? Now it doesn't matter.
vim "$(fzf)"
That opens whatever you pick.
The verdict
fzf is one of those tools where, a week in, you try to use someone else's terminal, press Ctrl-R, and feel genuinely betrayed. Install it, add the one line, and use Ctrl-R for a day. That's all it takes.
Your up-arrow key will thank you. It was getting tired.
Linux
More like this
Linux
entr and watch: Make Your Terminal Rerun Things So You Don't Have To
Save, switch window, press up, press Enter, squint. Save, switch window, press up... Stop. entr reruns your command whenever a file changes, and watch reruns it on a timer. Two tiny tools, a thousand saved keystrokes.
Linux
ripgrep: grep, But It Drank Three Espressos and Read Your .gitignore
grep is a legend. It's also happy to search all 80,000 files in node_modules while you wait. ripgrep searches only what matters, very quickly, with sensible defaults. The flags worth knowing, and when old grep still wins.
Linux
Linux Terminal Toys (and the Surprisingly Useful Tools Hiding Among Them)
A talking cow, a train that punishes typos, the Matrix in your terminal, and hidden among them, six genuinely useful tools you'll keep long after the novelty wears off. A toy box for Linux nerds.