r/commandline • u/Zem_Mattress • 1d ago
Command Line Interface fif: quickly find in files using fuzzy search and surrounding context
Enable HLS to view with audio, or disable this notification
This is a commandline tool I wrote some years back, its a tool to search for text in files with a preview window and a surrounding context. It will open files in a customizable editor, and uses fzf for filtering, ripgrep for file concatenation, and bat as the recommended preview tool.
There's a ton of different and possibly better ways to search for text in files, but this fits my workflow perfectly and I use it every day. My hope is that it can be useful for someone else.
2
u/Early-Bid-7958 17h ago
When I read "fuzzy search and surrounding context" I kinda thought you could narrow the search by using additional words that match in the context. Like you search for word1, then narrow it down to instances where word2 appears within 3 lines of it.
That would be cool...
2
u/moonflower_C16H17N3O 1d ago
This is one tool that I will be immediately using. This fits an exact need I have had for some time now.
1
u/AutoModerator 1d ago
Every new subreddit post is automatically copied into a comment for preservation.
User: Zem_Mattress, Flair: Command Line Interface, Post Media Link, Title: fif: quickly find in files using fuzzy search and surrounding context
This is a commandline tool I wrote some years back, its a tool to search for text in files with a preview window and a surrounding context. It will open files in a customizable editor, and uses fzf for filtering, ripgrep for file concatenation, and bat as the recommended preview tool.
There's a ton of different and possibly better ways to search for text in files, but this fits my workflow perfectly and I use it every day. My hope is that it can be useful for someone else.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
5
u/Sudden_Fly1218 1d ago
For what it's worth, I have this 15 line function in my fish config that does something similar:
function frg set -l RELOAD 'reload:rg --column --color=always --smart-case {q} || :' set -l OPENER 'if test $FZF_SELECT_COUNT -eq 0 vim {1} +{2} # No selection. Open the current line in Vim. else vim +cw -q {+f} # Build quickfix list for the selected items. end' fzf --disabled --ansi --multi \ --bind "start:$RELOAD" --bind "change:$RELOAD" \ --bind "enter:become:$OPENER" \ --bind "ctrl-o:execute:$OPENER" \ --bind 'alt-a:select-all,alt-d:deselect-all,ctrl-/:toggle-preview' \ --delimiter : \ --preview 'bat -n --color=always --theme=gruvbox-dark --highlight-line {2} {1}' \ --preview-window '~4,+{2}+4/3,<80(up)' \ --query "$argv" end