Control which files ripgrep searches
Scope ripgrep searches by glob, reveal hidden files, and inspect the file list before searching.
Updated
in short
Inspect the search scope with --files, then use a quoted glob and fixed-string matching to find a literal token.
Work through these disposable fixtures before adapting the commands to your own files. Run the steps in the same terminal session.
Tools used
Before you start
- Bash on Linux or macOS
- The listed tools installed and available on PATH
Steps
Step 1: Create a small source tree
The ignored directory and hidden file make the scope visible.
shtrmn_guide_dir="$(mktemp -d)" cd "$trmn_guide_dir" mkdir -p src vendor printf 'vendor/\n' > .ignore printf 'TODO ship endpoint\n' > src/app.py printf 'TODO draft docs\n' > notes.md printf 'TODO upstream fix\n' > vendor/library.py printf 'TODO rotate fixture\n' > .settingsStep 2: Inspect the default file set
Hidden files and paths matched by .ignore are omitted. Sorting keeps this example stable.
shrg --no-config --files | sortoutputnotes.md src/app.py
Step 3: Search just the Python files
Quote the glob so the shell leaves it for ripgrep. -F treats the token literally.
shrg --no-config --color never -n -F -g '*.py' TODO .output./src/app.py:1:TODO ship endpoint
Step 4: Include hidden files while preserving ignores
--hidden includes .settings; it does not disable .ignore. --no-ignore is a separate choice.
shrg --no-config --color never --hidden -n -F TODO . | sortoutput./.settings:1:TODO rotate fixture ./notes.md:1:TODO draft docs ./src/app.py:1:TODO ship endpoint
Further reading
[ripgrep guide](https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md) [ripgrep FAQ](https://github.com/BurntSushi/ripgrep/blob/master/FAQ.md)
FAQ
- Why use --no-config?
- It prevents a personal ripgrep configuration from changing the fixture results.
- Why does a search return exit code 1?
- For ripgrep, 1 means no match. Exit code 2 indicates an error. Account for this distinction when scripting.