| name | cli-fzf |
| description | Covers effective use of fzf (fuzzy finder) for interactive filtering of files, command history, processes, git branches, and any line-oriented data. Activates when the user asks about fzf, interactive selection from lists, fuzzy searching, or filtering command output interactively.
|
fzf — Fuzzy Finder
Repo: https://github.com/junegunn/fzf
Interactive fuzzy finder for the terminal. Pipe anything into fzf and get an
interactive, filterable selection UI. Works with files, history, processes,
git refs, environment variables, and any line-oriented data.
When to Activate
Manual triggers:
- "How do I use fzf?"
- "Fuzzy find files"
- "Interactive selection from a list"
- "Filter command output interactively"
Auto-detect triggers:
- User wants to interactively select from a large list of items
- User wants to search command history interactively
- User is combining fd/ripgrep output with selection
- User wants to kill a process by fuzzy-searching ps output
- User wants to switch git branches interactively
Key Commands
Basic Usage
fzf
fzf --height 40%
fzf --reverse
fzf --border
fzf --query "foo"
fzf --filter "foo"
fzf -m
fzf --select-1
fzf --exit-0
Shell Integration (set up in .bashrc/.zshrc)
$(brew install fzf && $(brew --prefix)/opt/fzf/install)
Preview Window
fzf --preview 'cat {}'
fzf --preview 'bat --color=always {}'
fzf --preview 'head -50 {}'
fzf --preview-window=right:60%
fzf --preview-window=up:30%
fzf --preview 'ls -la {}'
Key Bindings
fzf --bind 'ctrl-a:select-all'
fzf --bind 'ctrl-d:deselect-all'
fzf --bind 'ctrl-/:toggle-preview'
fzf --bind 'ctrl-y:execute(echo {} | pbcopy)'
fzf --bind 'ctrl-o:execute(open {})'
Advanced Patterns
Integration with fd (faster find)
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
fd --type f | fzf --preview 'bat --color=always {}'
Integration with ripgrep (search then select)
rg --line-number '' | fzf --delimiter ':' --preview 'bat --color=always --highlight-line {2} {1}'
fzf --disabled --ansi \
--bind "change:reload:rg --color=always --line-number {q} || true" \
--delimiter ':' \
--preview 'bat --color=always --highlight-line {2} {1}'
Kill a Process
kill -9 $(ps aux | fzf | awk '{print $2}')
ps aux | fzf --header-lines=1 | awk '{print $2}' | xargs kill -9
Git Branch Switching
git branch | fzf | xargs git checkout
git branch -a | sed 's/remotes\/origin\///' | fzf | xargs git checkout
git branch | fzf --preview 'git log --oneline --graph --date=short --color=always {}'
Git Log Navigation
git log --oneline --color=always | \
fzf --ansi --preview 'git show --color=always {1}' | \
awk '{print $1}' | xargs git show
Environment Variable Selection
env | fzf | cut -d= -f1
printenv $(env | fzf | cut -d= -f1)
SSH Host Selection
ssh $(awk '{print $1}' ~/.ssh/known_hosts | tr ',' '\n' | fzf)
Docker Container/Image Selection
docker exec -it $(docker ps | fzf --header-lines=1 | awk '{print $1}') bash
docker images | fzf -m --header-lines=1 | awk '{print $3}' | xargs docker rmi
tmux Integration
tmux list-sessions | fzf | cut -d: -f1 | xargs tmux switch-client -t
tmux list-windows | fzf | cut -d: -f1 | xargs tmux select-window -t
Practical Examples
Daily Workflows
$EDITOR $(fzf --preview 'bat --color=always {}')
cd $(find . -type d | fzf)
fzf | pbcopy
source $(find . -name '*.sh' | fzf)
FZF with Custom Input
echo -e "option1\noption2\noption3" | fzf
items=("apple" "banana" "cherry")
printf '%s\n' "${items[@]}" | fzf
cat package.json | jq -r '.scripts | keys[]' | fzf | xargs npm run
Useful Shell Functions
fcd() { cd "$(find ${1:-.} -type d | fzf)" }
fkill() { kill -9 $(ps aux | fzf | awk '{print $2}') }
flog() {
git log --oneline --color=always | fzf --ansi | awk '{print $1}' | xargs git checkout
}
fenv() { printenv $(env | fzf | cut -d= -f1) }
Configuration (~/.fzf.bash or ~/.fzf.zsh)
export FZF_DEFAULT_OPTS='
--height 40%
--layout=reverse
--border
--preview-window=right:50%:wrap
--bind ctrl-/:toggle-preview
'
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_ALT_C_COMMAND='fd --type d --hidden --follow --exclude .git'
Chaining with Other Skills
- fd (cli-fd): Use fd to generate a file list respecting .gitignore, pipe into fzf for interactive selection — far faster than
find | fzf
- ripgrep (cli-ripgrep): Use rg to search file contents, pipe results into fzf for interactive navigation to the exact line
- bat: Use
--preview 'bat --color=always {}' for syntax-highlighted file previews in fzf
- git/gh: Pipe
git branch, git log, gh pr list into fzf for interactive git workflows