Skip to content

fzf - a terminal fuzzy finder

By Brian Sunter

Posted in Terminal, Bash, Productivity

fzf terminal fuzzy finder
fzf terminal fuzzy finder

fzf is a terminal fuzzy finder tool that integrates nicely with many tools. These are a few of my favorite features.

Getting started

Install with hombrew and source completions in .zshrc

brew install fzf

$(brew --prefix)/opt/fzf/install

Shell History Search

Type CTRL-R to search your shell history for previously used commands

fzf history search

Interactive cd

Just type cd enter without arguments to enter "interactive cd". Each folder tree is searchable.

fzf interactive cd

fasd with fzf

you can integrate fzf frecency search with fzf

unalias z 2> /dev/null
z() {
[ $# -gt 0 ] && fasd_cd -d "$*" && return
local dir
dir="$(fasd -Rdl "$1" | fzf -1 -0 --no-sort +m)" && cd "${dir}" || return 1
}

fzf fasd

Chrome Terminal History Search

Just for fun you can search Google Chrome history with fzf from the terminal

# c - browse chrome history
c() {
local cols sep google_history open
cols=$(( COLUMNS / 3 ))
sep='{::}'

if [ "$(uname)" = "Darwin" ]; then
google_history="$HOME/Library/Application Support/Google/Chrome/Default/History"
open=open
else
google_history="$HOME/.config/google-chrome/Default/History"
open=xdg-open
fi
cp -f "$google_history" /tmp/h
sqlite3 -separator $sep /tmp/h \
"select substr(title, 1, $cols), url
from urls order by last_visit_time desc"
|
awk -F $sep '{printf "%-'$cols's \x1b[36m%s\x1b[m\n", $1, $2}' |
fzf --ansi --multi | sed 's#.*\(https*://\)#\1#' | xargs $open > /dev/null 2> /dev/null
}

fzf chrome history

CTRL-t

You can initiate a fzf file search in the middle of a terminal command by pressing CTRL-t together on your keyboard. This search is recursive from your current directory.

fzf ctrl-t

Brian Sunter
Brian Sunter

I've spent all my life on top of a mountain, learning the way of the Ninja Dev.