fzf
is a general-purpose command-line
fuzzy finder. On it's own it's not very useful but when combined with other
tools it becomes super powerful.
Use Homebrew to
install fzf
:
brew install fzf
If you want to use shell extensions (better shell integration):
/usr/local/opt/fzf/install
which gives you:
- Key bindings (
CTRL-T
,CTRL-R
, andALT-C
) (available for bash, zsh and fish) - Fuzzy auto-completion (available for bash and zsh)
Add any of these functions to your shell configuration file and apply the changes to try them out. Or just paste the function in your terminal if you just want to try it out without saving it.
# fd - cd to selected directory
fd() {
local dir
dir=$(find ${1:-.} -path '*/\.*' -prune \
-o -type d -print 2> /dev/null | fzf +m) &&
cd "$dir"
}
# fh - search in your command history and execute selected command
fh() {
eval $( ([ -n "$ZSH_NAME" ] && fc -l 1 || history) | fzf +s --tac | sed 's/ *[0-9]* *//')
}
For more fuzzy search examples see the official repo.
Note: original blog post
Open up your shell config and add following function:
# ch - browse chrome history
ch() {
local cols sep
cols=$(( COLUMNS / 3 ))
sep='{::}'
cp -f ~/Library/Application\ Support/Google/Chrome/Profile\ 1/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
}
Note: Ensure that path to History
file is correct; read more information
on StackOverflow.