Ramblings of an aging IT geek
← Ramblings of an aging IT geek
tooling

fzf rewired how i use the terminal

How a fuzzy finder bound into shell history, file search and git replaced a dozen half-remembered commands.

A mechanical keyboard lit by a terminal

For years my terminal workflow was a museum of half-remembered incantations. Ctrl-R to grope through history, hoping I'd typed enough of the command to find it. Long find pipelines I'd reconstruct from memory each time. A lot of cd ../../.. and squinting. Then I properly wired up fzf, and a surprising amount of that just went away.

The thing about fzf is not that it's a fuzzy finder. Plenty of tools fuzzy-match. It's that it reads lines on stdin and writes your selection to stdout, so it composes with everything. Once that clicked, I stopped thinking of it as a command and started thinking of it as a verb I could drop into any pipeline.

The bindings that earned their keep

The shipped shell integration gives you three things, and I use all three constantly. Ctrl-R becomes a proper fuzzy search over history with a preview. Ctrl-T inserts a fuzzy-selected file path into the current command line. Alt-C jumps into a fuzzy-selected directory. That last one quietly killed all my cd ../.. muscle memory.

The history one is the standout. I no longer need to remember the start of a command, just a distinctive fragment from the middle.

# in ~/.bashrc, after installing fzf
eval "$(fzf --bash)"
export FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border'

Terminal showing a fuzzy search overlay

Where it really pays off

The custom bits are where it stops being a nicety and starts being load-bearing. Switching git branches is the obvious one. I'd rather not type a branch name with three slashes and a ticket number in it.

gco() {
  git branch --all |
    grep -v HEAD |
    sed 's/.* //; s#remotes/[^/]*/##' |
    sort -u |
    fzf --preview 'git log --oneline --color=always {} | head -40' |
    xargs git checkout
}

The preview window is the part I underrated at first. Being able to see the last forty commits on a branch before I check it out, or the contents of a file before I open it, turns selection from a guess into a decision. I have a similar wrapper for killing processes, picking a Docker container, and choosing which stash to pop.

None of this is clever. It's the same Unix idea it always was: small tools, text streams, glue. fzf is just unusually good glue. The payoff is that I've stopped holding so much trivia in my head. The terminal remembers the paths and the branch names; I get to spend that memory on something that matters. If you only adopt one new tool this year, you could do a lot worse.