Ripgrep: Feature Request: flag to search filenames in addition to contents

Created on 2 Sep 2018  路  4Comments  路  Source: BurntSushi/ripgrep

What version of ripgrep are you using?

ripgrep 0.9.0
-SIMD -AVX

How did you install ripgrep?

brew

What operating system are you using ripgrep on?

Darwin 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64 x86_64

Describe your question, feature request, or bug.

A flag (perhaps --search-names-and-contents or --also-search-filenames ?) that will allow searching both file contents and file names as part of the same invocation. i.e. for the hypothetical

rg --search-names-and-contents pattern dir

the output would be the (interleaved) equivalent of

rg --files -g '*pattern*' dir
rg pattern dir

I know that rg isn't intended to be a find replacement, but I often am searching through very large dir structures for files that either contain a given string OR where their filename contains that string, and running rg twice (or rg once and fd once, which is what I currently do) on the same huge dir structure (hundreds of thousands of files) is very inefficient, and having the output not interleaved because it is generated by two commands also makes it harder to read.

question

Most helpful comment

For anyone arriving here from Google, use fd instead, to search files by filename: https://github.com/sharkdp/fd
It has similar improvements to rg (e.g. automatic .gitignore exclusions)

All 4 comments

I don't think this is a good fit for ripgrep. I understand the use case, but ripgrep isn't a tool for searching file names. It's a tool for searching files. For example, there are several things that aren't considered in this feature request:

  1. The match semantics of -g '*pattern*' are of globs, not regexes.
  2. Emitting a file path without any of its contents seems weird to me. There is no way for that to happen today. Each matching file contains at least one line.
  3. How is a regex applied to a file path? Is it only the base name? The entire path? Something else?
  4. It seems like if this flag were added, it would be natural to ask for a flag that is "search only file names." In other words, it's a feature that begets more features, which doesn't excite me.

I've thought about this more, and I'd like to keep ripgrep focused on searching files for now.

Needing to do two searches is somewhat unfortunate, but one of those searches only needs to look at file paths, which should be much quicker to execute.

For anyone arriving here from Google, use fd instead, to search files by filename: https://github.com/sharkdp/fd
It has similar improvements to rg (e.g. automatic .gitignore exclusions)

@fregante I would have mentioned that, but note that this feature request is subtly different than just searching the contents of file names. The requested feature is to search _both_ file names _and_ file contents simultaneously for the same pattern.

Was this page helpful?
0 / 5 - 0 ratings