BurntSushi/ripgrep
File typing
ripgrep can filter files by language using human-friendly type names: rg -tpy 'foo' only searches Python files, rg -Tjs 'foo' excludes JavaScript files.
Where the types come from
A "file type" is a name (string) plus a list of globs. The defaults live in crates/ignore/src/default_types.rs as a static array. As of writing the table holds well over 250 entries — rust, py, js, ts, cpp, cmake, dockerfile, yaml, markdown, ... — each mapped to its conventional file extensions.
Users can extend or override this table via:
--type-add 'foo:*.fooext,*.barext'— adds a new type or appends globs to an existing one.--type-clear NAME— wipes a type's globs (so a subsequent--type-addstarts fresh).--type NAME(-tNAME) — only search files matching the type's globs.--type-not NAME(-TNAME) — exclude files matching the type's globs.
Multiple -t and -T flags are allowed; the union of types is included and the union of negated types is excluded.
Listing types
rg --type-list prints the full registered type table (defaults plus any --type-add from configuration). Output is name: glob1, glob2, glob3. The implementation is in crates/core/main.rs::types, which iterates args.types().definitions().
Implementation pipeline
graph TD
Defaults["default_types::DEFAULT_TYPES (static array)"] --> Builder[TypesBuilder]
UserAdd["--type-add user input"] --> Builder
UserClear["--type-clear"] --> Builder
Builder --> Types["compiled Types matcher (GlobSet)"]
UserSelect["-t / -T flags"] --> Selector[Selector]
Selector --> Types
Types --> Walker[WalkBuilder]
Walker --> Filescrates/ignore/src/types.rs defines Types and TypesBuilder. The builder collects definitions, parses each glob, and at build() time emits a single Types matcher backed by a GlobSet. The Types matcher is then plugged into the walker as one of the priority layers (see gitignore handling for the precedence diagram).
Types::matched returns one of:
Match::None— type matchers don't apply (no-tor-Tselected anything).Match::Ignore(Glob)— a-Tselector matched; file is excluded.Match::Whitelist(Glob)— a-tselector matched; file is whitelisted.
The walker's per-directory ignore stack consults Types after Override (CLI globs) and before .gitignore.
Configuring through RIPGREP_CONFIG_PATH
Per-line CLI flags in the config file are equivalent to the same flags on the command line, including --type-add. So:
# ~/.config/ripgrep/ripgreprc
--type-add=fooext:*.foo
--type-add=fooext:*.foo2…is equivalent to passing those flags on every invocation. The config-file parser is crates/core/flags/config.rs.
Reference: file & function pointers
| What | Where |
|---|---|
| Default-type table | crates/ignore/src/default_types.rs |
Types, TypesBuilder, Selection |
crates/ignore/src/types.rs |
Type matcher integration with WalkBuilder |
crates/ignore/src/walk.rs |
--type, --type-not, --type-add, --type-clear, --type-list flags |
crates/core/flags/defs.rs |
--type-list output handler |
crates/core/main.rs::types |
For the user-facing GUIDE see https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md#manual-filtering-file-types.
Adding a new default type
The most common ripgrep contribution is "please add a default type for X". The procedure:
- Identify the conventional file extensions.
- Add an entry to
DEFAULT_TYPESincrates/ignore/src/default_types.rskeeping the array sorted. - Add a
tests/feature.rstest that exercises-t newtypeagainst a fixture file. - Add a one-line entry to
CHANGELOG.mdunder "Many enhancements to the default set of file types" or as a standalone bullet.
The CHANGELOG cites Lean and Meson as recent additions (14.1.0).
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.