Fuzzy finders are very useful tools to skim through long lists of results by filtering those items that approximately match a given string(s). In Linux, we can get a fuzzy finder right in the terminal with fzf.
We can also make a very simple fuzzy finder by using grep in a recursive function in bash. The goal is to consecutively match the input text with each and all pattern strings in the argument list. This can serve as a rudimentary solution if fzf is not available in your system (or, you know, just for fun! :sunglasses:).
Recursive grep
The following recursive function (called rgrep) picks the top pattern string in the argument list, executes grep on the input to match that pattern, shifts the arguments and passes the result to itself.
function rgrep { if [ "$1" ]; then local pattern="$1" if [ "$2" ]; then shift grep -- "$pattern" | rgrep "$@" else grep -- "$pattern" fi fi}
The result is equivalent to performing a logical AND on all patterns with the command
Our new command rgrep can be easily applied to any command that prints lists of results, such as history. For instance, I set hgrep as the following alias to easily find commands in
my history log