summaryrefslogtreecommitdiffstats
path: root/src/args.rs
diff options
context:
space:
mode:
authordana <dana@dana.is>2018-01-11 17:45:51 -0600
committerAndrew Gallant <jamslam@gmail.com>2018-01-11 18:45:51 -0500
commit58bdc366ec292653124699940190432ae30a6732 (patch)
treeb9f57e7d3502bf23452a0c0445edd593c628f402 /src/args.rs
parent34c0b1bc709f74678d7c1a24046c26571c25eaec (diff)
printer: add --passthru flag
The --passthru flag causes ripgrep to print every line, even if the line does not contain a match. This is a response to the common pattern of `^|foo` to match every line, while still highlighting things like `foo`. Fixes #740
Diffstat (limited to 'src/args.rs')
-rw-r--r--src/args.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/args.rs b/src/args.rs
index 6affa2dd..d2d0232b 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -433,7 +433,9 @@ impl<'a> ArgMatches<'a> {
/// Note that if -F/--fixed-strings is set, then all patterns will be
/// escaped. Similarly, if -w/--word-regexp is set, then all patterns
/// are surrounded by `\b`, and if -x/--line-regexp is set, then all
- /// patterns are surrounded by `^...$`.
+ /// patterns are surrounded by `^...$`. Finally, if --passthru is set,
+ /// the pattern `^` is added to the end (to ensure that it works as
+ /// expected with multiple -e/-f patterns).
///
/// If any pattern is invalid UTF-8, then an error is returned.
fn patterns(&self) -> Result<Vec<String>> {
@@ -470,7 +472,11 @@ impl<'a> ArgMatches<'a> {
}
}
}
- if pats.is_empty() {
+ // It's important that this be at the end; otherwise it would always
+ // match first, and we wouldn't get colours in the output
+ if self.is_present("passthru") && !self.is_present("count") {
+ pats.push("^".to_string())
+ } else if pats.is_empty() {
pats.push(self.empty_pattern())
}
Ok(pats)