Ripgrep is a tool used for searching for files through your computer’s terminal. It’s based off another tool called grep. The difference between the two is that ripgrep will read your .gitignore file thereby being a lot faster
Here is where you can read up on .gitignore if you want more info.
brew install ripgrep
yum-config-manager --add-repo=https://copr.fedorainfracloud.org/coprs/carlwgeorge/ripgrep/repo/epel-7/carlwgeorge-ripgrep-epel-7.repo
yum install ripgrep
choco install ripgrep
Confirm that you have it by typing in this:
rg --version
Its speed is quite fast, it defaults to recursively searching your directories where it’ll use your .gitignore,.ignore, or finally your .rgignore file. It ignores hidden and binary files by default. You can use it to search specific files like this:
rg nextInt -tgo
This is saying that we want to search for the text nextInt
only where the files have the .go extension. It shows us that we have results on lines 13,15,16, and 17.
The thing that I love about Ripgrep compared to other search tools is that you can supply custom parameters to search through files that ripgrep might not know how to search.
The real beauty of ripgrep is that you can customize it. Some tools like the Silver Searcher (ag) are also fast, but if there’s a filetype that it doesn’t recognize, I can’t filter by it1.
Here’s a small example of using Java. I am wanting to search for the text apple in the code, but in this case, I don’t care about property files.
My response when many files show up that didn’t get filtered.
Yet, I can fix this by either typing this code below in the terminal for a one time case, or by creating an alias so I can always exclude property files when I’m searching Java. Note, this is just an example, you should be careful what you filter.
Here is the alias.
alias rg="rg --type-add 'java:*.java' -g '!*.properties'"
I have not tested this. Your milage may vary.
set "rg=rg --type-add 'java:*.java' -g '!*.properties'"
It’s now searching Java, but excluding property files.
You can click here if you want more info on what ripgrep is capable of.
It might be possible to do custom file filtering in ag, I just haven’t come across it and I have gotten used to using ripgrep for my searches. If you find out how to do it in ag, I’d love to hear about it. ↩︎