Last active
July 13, 2023 05:24
-
-
Save TripleDogDare/170cf93be8f4bd1f5dcbef26ad41246b to your computer and use it in GitHub Desktop.
An interactive fuzzy grep showing surrounding context
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
This doesn't work like a normal
grep
commandusage:
I primarily use this to search help documents.
But you can searching logs is useful as well