summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordana <dana@dana.is>2019-08-01 16:08:58 -0500
committerAndrew Gallant <jamslam@gmail.com>2019-08-01 17:08:58 -0400
commitc2cb0a4de4597c8f911c8ebece6aa0435ef5da6f (patch)
tree130944b7519d3a089444d0ec3695e21c12ec95f7
parentadb9332f52b884c8b872d1c969a7841188fe3089 (diff)
ripgrep: add --glob-case-insensitive
This flag forces -g/--glob patterns to be treated case-insensitively, as with --iglob patterns. Fixes #1293
-rw-r--r--complete/_rg4
-rw-r--r--src/app.rs20
-rw-r--r--src/args.rs4
-rw-r--r--tests/misc.rs8
4 files changed, 36 insertions, 0 deletions
diff --git a/complete/_rg b/complete/_rg
index f7315c00..d7dcfd64 100644
--- a/complete/_rg
+++ b/complete/_rg
@@ -104,6 +104,10 @@ _rg() {
'*'{-g+,--glob=}'[include/exclude files matching specified glob]:glob'
'*--iglob=[include/exclude files matching specified case-insensitive glob]:glob'
+ + '(glob-case-insensitive)' # File-glob case sensitivity options
+ '--glob-case-insensitive[treat -g/--glob patterns case insensitively]'
+ $no'--no-glob-case-insensitive[treat -g/--glob patterns case sensitively]'
+
+ '(heading)' # Heading options
'(pretty-vimgrep)--heading[show matches grouped by file name]'
"(pretty-vimgrep)--no-heading[don't show matches grouped by file name]"
diff --git a/src/app.rs b/src/app.rs
index fa322817..d69d5cd7 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -571,6 +571,7 @@ pub fn all_args_and_flags() -> Vec<RGArg> {
flag_fixed_strings(&mut args);
flag_follow(&mut args);
flag_glob(&mut args);
+ flag_glob_case_insensitive(&mut args);
flag_heading(&mut args);
flag_hidden(&mut args);
flag_iglob(&mut args);
@@ -1218,6 +1219,25 @@ it.
args.push(arg);
}
+fn flag_glob_case_insensitive(args: &mut Vec<RGArg>) {
+ const SHORT: &str = "Process all glob patterns case insensitively.";
+ const LONG: &str = long!("\
+Process glob patterns given with the -g/--glob flag case insensitively. This
+effectively treats --glob as --iglob.
+
+This flag can be disabled with the --no-glob-case-insensitive flag.
+");
+ let arg = RGArg::switch("glob-case-insensitive")
+ .help(SHORT).long_help(LONG)
+ .overrides("no-glob-case-insensitive");
+ args.push(arg);
+
+ let arg = RGArg::switch("no-glob-case-insensitive")
+ .hidden()
+ .overrides("glob-case-insensitive");
+ args.push(arg);
+}
+
fn flag_heading(args: &mut Vec<RGArg>) {
const SHORT: &str = "Print matches grouped by each file.";
const LONG: &str = long!("\
diff --git a/src/args.rs b/src/args.rs
index cd217b4b..09f924dc 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -1268,6 +1268,10 @@ impl ArgMatches {
/// Builds the set of glob overrides from the command line flags.
fn overrides(&self) -> Result<Override> {
let mut builder = OverrideBuilder::new(env::current_dir()?);
+ // Make all globs case insensitive with --glob-case-insensitive.
+ if self.is_present("glob-case-insensitive") {
+ builder.case_insensitive(true).unwrap();
+ }
for glob in self.values_of_lossy_vec("glob") {
builder.add(&glob)?;
}
diff --git a/tests/misc.rs b/tests/misc.rs
index 8c162674..c122f5f5 100644
--- a/tests/misc.rs
+++ b/tests/misc.rs
@@ -341,6 +341,14 @@ rgtest!(glob_case_sensitive, |dir: Dir, mut cmd: TestCommand| {
eqnice!("file2.html:Sherlock\n", cmd.stdout());
});
+rgtest!(glob_always_case_insensitive, |dir: Dir, mut cmd: TestCommand| {
+ dir.create("sherlock", SHERLOCK);
+ dir.create("file.HTML", "Sherlock");
+ cmd.args(&["--glob-case-insensitive", "--glob", "*.html", "Sherlock"]);
+
+ eqnice!("file.HTML:Sherlock\n", cmd.stdout());
+});
+
rgtest!(byte_offset_only_matching, |dir: Dir, mut cmd: TestCommand| {
dir.create("sherlock", SHERLOCK);
cmd.arg("-b").arg("-o").arg("Sherlock");