Find in file using ripgrep, then fuzzy find matched filenames with fzf, preview match using bat
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
fif() { | |
rg \ | |
--column \ | |
--line-number \ | |
--no-column \ | |
--no-heading \ | |
--fixed-strings \ | |
--ignore-case \ | |
--hidden \ | |
--follow \ | |
--glob '!.git/*' "$1" \ | |
| awk -F ":" '/1/ {start = $2<5 ? 0 : $2 - 5; end = $2 + 5; print $1 " " $2 " " start ":" end}' \ | |
| fzf --preview 'bat --wrap character --color always {1} --highlight-line {2} --line-range {3}' --preview-window wrap | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Slight variant that leverages a key binding (ctrl+o) for opening the file in vscode at the proper line and column while selected in fzf
The output from
awk
expression is in the form of:<filename> <linenum> <col> <linenum-5>:<linenum+5>
fzf
lets you access the different space separated fields from its input using the{num}
syntaxThe syntax for opening a file at specified line and column in vscode is
code --goto <filename>:<line>:<column>