diff --git a/src/app.rs b/src/app.rs index 89dac06..4865126 100644 --- a/src/app.rs +++ b/src/app.rs @@ -35,7 +35,8 @@ pub fn build_app() -> App<'static, 'static> { .arg(arg("hidden").long("hidden").short("H")) .arg(arg("no-ignore").long("no-ignore").short("I")) .arg(arg("rg-alias-hidden-ignore").short("u").multiple(true).hidden(true)) - .arg(arg("case-sensitive").long("case-sensitive").short("s")) + .arg(arg("case-sensitive").long("case-sensitive").short("s").overrides_with("ignore-case")) + .arg(arg("ignore-case").long("ignore-case").short("i").overrides_with("case-sensitive")) .arg(arg("absolute-path").long("absolute-path").short("a")) .arg(arg("follow").long("follow").short("L").alias("dereference")) .arg(arg("full-path").long("full-path").short("p")) @@ -98,6 +99,10 @@ fn usage() -> HashMap<&'static str, Help> { , "Case-sensitive search (default: smart case)" , "Perform a case-sensitive search. By default, fd uses case-insensitive searches, \ unless the pattern contains both upper- and lowercase characters (smart case)."); + doc!(h, "ignore-case" + , "Case-insensitive search (default: smart case)" + , "Perform a case-insensitive search. By default, fd uses case-insensitive searches, \ + unless the pattern contains both upper- and lowercase characters (smart case)."); doc!(h, "absolute-path" , "Show absolute instead of relative paths" , "Shows the full path starting from the root as opposed to relative paths."); diff --git a/src/internal.rs b/src/internal.rs index 9aff14e..1c1d66a 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -24,7 +24,7 @@ pub enum PathDisplay { /// Configuration options for *fd*. pub struct FdOptions { - /// Determines whether the regex search is case-sensitive or case-insensitive. + /// Whether the search is case-sensitive or case-insensitive. pub case_sensitive: bool, /// Whether to search within the full file path or just the base name (filename or directory diff --git a/src/main.rs b/src/main.rs index 49eb741..277aae8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,8 +62,11 @@ fn main() { // The search will be case-sensitive if the command line flag is set or // if the pattern has an uppercase character (smart case). - let case_sensitive = matches.is_present("case-sensitive") || - pattern.chars().any(char::is_uppercase); + let case_sensitive = if !matches.is_present("ignore-case") { + matches.is_present("case-sensitive") || pattern.chars().any(char::is_uppercase) + } else { + false + }; let colored_output = match matches.value_of("color") { Some("always") => true, diff --git a/tests/tests.rs b/tests/tests.rs index ec10391..5322946 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -115,6 +115,26 @@ fn test_case_sensitive() { te.assert_output( &["--case-sensitive", "C.Foo"], "one/two/C.Foo2"); + + te.assert_output( + &["--ignore-case", "--case-sensitive", "C.Foo"], + "one/two/C.Foo2"); +} + +/// Case insensitivity (--ignore-case) +#[test] +fn test_case_insensitive() { + let te = TestEnv::new(); + + te.assert_output( + &["--ignore-case", "C.Foo"], + "one/two/c.foo + one/two/C.Foo2"); + + te.assert_output( + &["--case-sensitive", "--ignore-case", "C.Foo"], + "one/two/c.foo + one/two/C.Foo2"); } /// Full path search (--full-path)