FZF Mastery: The Interactive Glue๐
Part of a pathway: Debugging With Nothing But a Terminal
Consult the map
-
Debugging With Nothing But a Terminal โ step 14 of 20
โ tmux ยท you are here ยท Multiple AI CLIs, One tmux Session โ
Basic history searching (Ctrl+r) is most people's first and only use of fzf. But fzf is more than a history tool โ it's a universal interactive filter, the "glue" that turns static lists into interactive workflows. This is how custom CLI interfaces get built.
fzf takes any list of text, lets you filter it in real-time, and outputs your selection. This simple primitive can be combined with almost any other tool to create powerful, custom workflows.
Installation๐
- Sets up the
Ctrl+rhistory andCtrl+tfile-widget key bindings for your shell.
The Core Concept: One Filter, Many Lists๐
The same primitive sits in front of almost any list you'd otherwise scroll through by hand:
graph LR
Files["File names"] --> FZF{{"fzf"}}
Procs["Process list"] --> FZF
Branches["Git branches"] --> FZF
Pods["Pod names"] --> FZF
FZF --> Open["Open in editor"]
FZF --> Kill["Kill selected"]
FZF --> Checkout["Checkout branch"]
FZF --> Logs["Tail logs"]
style Files fill:#2d3748,stroke:#cbd5e0,stroke-width:2px,color:#fff
style Procs fill:#2d3748,stroke:#cbd5e0,stroke-width:2px,color:#fff
style Branches fill:#2d3748,stroke:#cbd5e0,stroke-width:2px,color:#fff
style Pods fill:#2d3748,stroke:#cbd5e0,stroke-width:2px,color:#fff
style FZF fill:#d69e2e,stroke:#cbd5e0,stroke-width:2px,color:#000
style Open fill:#2f855a,stroke:#cbd5e0,stroke-width:2px,color:#fff
style Kill fill:#2f855a,stroke:#cbd5e0,stroke-width:2px,color:#fff
style Checkout fill:#2f855a,stroke:#cbd5e0,stroke-width:2px,color:#fff
style Logs fill:#2f855a,stroke:#cbd5e0,stroke-width:2px,color:#fff
Every alias and scenario below is the same shape: pipe a list in, get one selection out, hand it to the next command.
Quick Start: The One-Liners๐
Add these to your aliases for immediate impact:
| FZF Multipliers | |
|---|---|
Why FZF Matters for Platform Work๐
SREs spend their time navigating complex namespaces and large numbers of resources. fzf allows you to navigate these without having to memorize names or copy-paste from the terminal.
Common Scenarios๐
Stop typing pod names manually. Select from a live list:
Select multiple containers to stop and remove at once:
Advanced FZF Features๐
Three flags turn a basic selector into a real interface:
-
The Preview Window
Why it matters: See the contents of a file or the details of a resource before you select it, instead of guessing from the filename alone.
Preview Files While Filtering -
Multi-Select (
-m)
Why it matters: Select multiple items using
Tab, then act on all of them at once. Perfect for bulk operations like deleting a batch of files or stopping several services.Select Multiple Files, Then Remove Them -
Custom Bindings
Why it matters: Bind keys within
fzfitself to perform actions on the highlighted item, without exiting the selector first.Open a File in Vim Without Leaving fzf
Practice Problems๐
Practice Problem 1: Previews
How would you create an fzf command that lists all files in the current directory and shows a preview of the first 10 lines of each file as you move through the list?
Answer
| Preview First 10 Lines of Each File | |
|---|---|
Practice Problem 2: Extraction
When you pipe ps -ef into fzf, the output contains many columns. How do you extract just the PID (the second column) of the selected line?
Answer
| Extract the PID Column from a Selection | |
|---|---|
awk is the perfect partner for fzf when you need to extract specific fields from a structured line of text.
Key Takeaways๐
| Feature | Flag | Purpose |
|---|---|---|
| Multi-select | -m or --multi |
Select multiple items with Tab |
| Preview | --preview 'cmd' |
Run a command on the current item |
| Prompt | --prompt 'text' |
Change the input prompt |
| Header | --header 'text' |
Add a static header at the top |
| Exact Match | -e |
Use exact matching instead of fuzzy |
What's Next๐
If you're following the Debugging With Nothing But a Terminal pathway, the next step is Multiple AI CLIs, One tmux Session โ filtering one list interactively is one pane's worth of work; the next step is running several panes at once and moving answers between them.
Further Reading๐
Official Documentation๐
- fzf Wiki: Examples - A treasure trove of community-built functions.
- fzf Manual - Detailed reference for all flags and bindings.
Related Tools & Alternatives๐
Deep Dives๐
- Pipes and Redirection - The core Unix philosophy โ small tools connected by pipes โ that makes
fzfso powerful as connective tissue.