TIL: fzf's --preview can run arbitrary shell commands
I thought --preview was for files. It’s for anything.
# preview file contents
fzf --preview 'bat --color=always {}'
# preview directory structure
fzf --preview 'tree -C {} | head -100'
# preview git log for a branch
git branch | fzf --preview 'git log --oneline --color=always {}'
# preview kubectl pod description
kubectl get pods | fzf --header-lines=1 --preview 'kubectl describe pod $(echo {} | awk "{print \$1}")'
# preview DNS lookup for hostnames
cat /etc/hosts | fzf --preview 'host $(echo {} | awk "{print \$2}")'
The {} in the preview template gets replaced with the current line. You can pipe, awk, compose as needed. It runs on every selection change, so heavy commands will feel sluggish — prefer things that complete in well under a second.
Handy variants:
--preview-window=up:30%— put the preview on top, smaller.--preview-window=hidden— start hidden, toggle with a bound key.--bind '?:toggle-preview'— bind?to show/hide the preview.
This one-liner is now in my shell:
alias fkill='ps aux | fzf --preview "echo {} | awk \"{print \\\$2}\" | xargs -I{} cat /proc/{}/status 2>/dev/null" | awk "{print \$2}" | xargs -r kill'
fkill lets me pick a process from a fuzzy list with a live preview of its status before killing it. Quality of life, unlocked.