Skip to content

Commit 4ef4818

Browse files
committed
No line numbers when searching only stdin.
This changes the default behavior of ripgrep to *not* show line numbers when it is printing to a tty and is only searching stdin. Fixes #380 [breaking-change]
1 parent 8db24e1 commit 4ef4818

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/args.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ impl<'a> ArgMatches<'a> {
319319
/// configuration.
320320
fn to_args(&self) -> Result<Args> {
321321
let paths = self.paths();
322+
let line_number = self.line_number(&paths);
322323
let mmap = try!(self.mmap(&paths));
323324
let with_filename = self.with_filename(&paths);
324325
let (before_context, after_context) = try!(self.contexts());
@@ -345,7 +346,7 @@ impl<'a> ArgMatches<'a> {
345346
hidden: self.hidden(),
346347
ignore_files: self.ignore_files(),
347348
invert_match: self.is_present("invert-match"),
348-
line_number: self.line_number(),
349+
line_number: line_number,
349350
line_per_match: self.is_present("vimgrep"),
350351
max_count: try!(self.usize_of("max-count")).map(|max| max as u64),
351352
max_filesize: try!(self.max_filesize()),
@@ -593,13 +594,14 @@ impl<'a> ArgMatches<'a> {
593594
}
594595

595596
/// Returns true if and only if line numbers should be shown.
596-
fn line_number(&self) -> bool {
597+
fn line_number(&self, paths: &[PathBuf]) -> bool {
597598
if self.is_present("no-line-number") || self.is_present("count") {
598599
false
599600
} else {
601+
let only_stdin = paths == &[Path::new("-")];
600602
self.is_present("line-number")
601603
|| self.is_present("column")
602-
|| atty::is(atty::Stream::Stdout)
604+
|| (atty::is(atty::Stream::Stdout) && !only_stdin)
603605
|| self.is_present("pretty")
604606
|| self.is_present("vimgrep")
605607
}

0 commit comments

Comments
 (0)