2025-06-02 Ripgrep a nice Rust utility for ports spelunking
In keeping with the talking blabbing about the Rust ecosystem theme let's talk about a tool I have found invaluable when I work on the command line. The utility is called ripgrep and I have found it useful when crawling the ports tree for more information about ports. Some of the pros that I found of using ripgrep in this instance are:
simpler syntax to remember
faster than a typical find-grep pipeline
color highlighting
cross platform (thanks Rust)
Here is an example usage scenario. How many occurrences of the word cargo (which is a strong indicator that the port is a Rust port) occur in the ports tree?
Let's check it out. Here is a typical find-grep pipeline that attempts to find occurrences of term cargo in the ports tree
$ cd /usr/ports
$ find . -type f -name Makefile -print0 | xargs -0 grep -E cargo | time wc -l
876
19.10 real 0.00 user 0.00 sys
Here is a similar (and lazier) check using ripgrep.
$ cd /usr/ports
$ time rg -l cargo | wc -l
6.68 real 6.57 user 19.21 sys
948
Note that the actual count is off as ripgrep actually searched more files than the find-grep pipeline. The find-grep pipeline filtered just for Makefiles while ripgrep did not. That means in this example, ripgrep had to do more work. However, according to the output, ripgrep is faster in returning results (~7s versus ~19s) than the find-grep example by a decent margin.
Searching for terms inside of a pile of files in filesystem trees is something I have found ripgrep easier (and quicker) to deal with compared to find-grep pipeline. Perhaps it is so convenient that it is in danger of making my ability to recall find-grep syntax even worse than it already is. (I do not plan on giving up using find-grep pipelines where it makes sense)
Well if the results convinced to try ripgrep (on FreeBSD) then how do I get it? It's pretty simple in FreeBSD since it's already packaged up.
For a package install
$ pkg install ripgrep
For a ports install
cd /usr/ports/sysutils/ripgrep
make && doas make install
Enjoy!