I just discovered fzf, a lightning fast fuzzy
search you can integrate into almost everything. I found it to be super useful
as a replacement for the ctrl+r
shell history search.
^r
now looks like this:
There are a couple of plugins for this purpose, but I like to avoid a plugin manager and keep my zsh config clean. So I wrote it from scratch.
On a Mac, you install fzf easiest with Homebrew:
brew install fzf
Here's my configuration from my ~/.zshrc
.
# fzf history
fzf_history_search() {
export LC_ALL=C # reset locales to avoid issues with cut
BUFFER=$(eval cat ~/.zsh_history | cut -d ';' -f 2 | awk '!x[$0]++' | fzf -e --preview-window=hidden --tac -q "$BUFFER")
zle end-of-line; # move cursor to end of line
}
autoload fzf_history_search
zle -N fzf_history_search
bindkey '^r' fzf_history_search # Bind Ctrl+r to fzf_history_search