Fuzzy search through multiple files
When I do rg foo /bar/baz/
, ripgrep will search for foo
in all files under /bar/baz/
. For every file that has matching lines, it will print each line with its line number, highlight the matching part, and also caption the lines with the name of the file as well. The filenames are a different color to make them stand out more. I can use the --context
, --after-context
, --before-context
lines to include additional lines around the matching line.
This is great but the one problem is it's an exact search. How can I do the same thing, with the same type of output, but fuzzy instead?
It seems like fzf should help, but I have no idea what magic incantation of fzf arguments is needed for this. I would need it to be not interactive (so that I can use it in pipelines and scripts), include line numbers and file names just like ripgrep, have an option for context just like ripgrep, ideally colorize like ripgrep.
I suppose with fuzzy matching, it is arbitrary what to consider a "match", and technically all lines of all files are a "weak match". But by default fzf appears to have some cutoff, and I'm okay with just using that.
0 comment threads