Skip to content

Commit

Permalink
ripgrep: add --glob-case-insensitive
Browse files Browse the repository at this point in the history
This flag forces -g/--glob patterns to be treated case-insensitively, as with
--iglob patterns.

Fixes BurntSushi#1293
  • Loading branch information
okdana committed Jun 6, 2019
1 parent 392682d commit aed6149
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions complete/_rg
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand Down
20 changes: 20 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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!("\
Expand Down
4 changes: 4 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
Expand Down
8 changes: 8 additions & 0 deletions tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit aed6149

Please sign in to comment.