Ripgrep Config File

1 April, 2024 - Tags: til, ripgrep


When you invoke rg then you can have an exported environment variable pointing to a config and then ripgrep will consider that as default when you run it.

For example: I almost never want to search anything in .git or vendor directory. Up until now, I used -g !vendor to avoid it. I had an abbreviations in my fish config for the same but I think having a default config file is much better than passing the command line flags.

Here's how I did it.

$ cat ~/.config/rg/ripgreprc
# Using glob patterns to include/exclude files or folders
--glob=!vendor/*
--glob=!.git/*

Once this is installed, I exported an environment variable if ripgrep is installed on my system using my fish config file.

if command -v rg &> /dev/null
    set -x RIPGREP_CONFIG_PATH $HOME/.config/rg/ripgreprc
end

And now whenever I search I don't get result from vendor directory out of the box.

I also don't invoke rg directly these days and use the TUI of ripgrep https://github.com/konradsz/igrep and the good thing is that this project supports the config file mentioned above.