Finding Text in Files Ergonomically - Announcing recent-rgrep
17 Jan 2025 Charles Choi
Searching for text in a directory tree of files is a commonplace task. For people who use plain text files there are a number of tools that can accomplish this. One such tool that is ubiquitous in Unix-flavored (predominantly Linux and macOS) systems is the command line utility grep
. Emacs builds on this with the rgrep
command, invoking grep
recursively and presenting its results in a grep-mode
buffer. In other editors and IDEs, this feature is named “Find in Files” or “Find in Project”.
Recently I went down the rabbit hole of wanting to get the results of rgrep
but with the following twist: report the match results in order of recently modified file, descending. The implementation I ended up with is a two-pass solution that’s brute force but effective.
Announcing recent-rgrep, available on GitHub.
Features
- Reports matches in order most recently modified files descending (that is, the most recent files are reported first).
- Search only in non-binary files.
- Avoids searching in common SCM directories (
.git
,.hg
,.svn
,.cvs
). - Uses the existing
grep
that you have installed on your system. - Default search is case-insensitive.
- Supports usage from both the command line and Emacs.
What about ripgrep?
NGL, you’re likely better off using ripgrep if you have it installed. But if not, then this modest script can achieve the desired result described above.
Closing Thoughts
If this all seems interesting, I invite you to try recent-rgrep
out. In practice, I’ve found it to make my searches more effective as I’m usually more interested in the files that I last worked on. While there’s a performance hit with making two passes, I generally don’t encounter it in the places I use it. YMMV.