Skip to content

Instantly share code, notes, and snippets.

@tecfu
Forked from TripleDogDare/fzgrep
Created July 13, 2023 05:24
Show Gist options
  • Save tecfu/97fe828fde03fa558307450e8a9431ef to your computer and use it in GitHub Desktop.
Save tecfu/97fe828fde03fa558307450e8a9431ef to your computer and use it in GitHub Desktop.
An interactive fuzzy grep showing surrounding context
#!/bin/bash
set -euo pipefail
# go get github.com/junegunn/fzf
BEFORE=10
AFTER=10
HEIGHT=$(expr $BEFORE + $AFTER + 3 ) # 2 lines for the preview box and 1 extra line fore the match
PREVIEW="$@ 2>&1 | grep --color=always -B${BEFORE} -A${AFTER} -F -- {}"
"$@" 2>&1 | fzf --height=$HEIGHT --reverse --preview="${PREVIEW}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment