Add -i, --ignore-case
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by J.W · committed by David Peter · parent 35e5ecd · Browse files · 4 files·+32 added−4 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+32 added−4 removed
- tests:+20 added−0 removed
- other:+12 added−4 removed
Provenance
- Commit
e075e1c- Tree
bf4bd04- Author
J.W <jakwings@gmail.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
35e5ecd
4 files changed+32 added−4 removed
modified:src/app.rs+6 added-1 removed
33 unmodified lines34 .setting(AppSettings::DeriveDisplayOrder)35 .arg(arg("hidden").long("hidden").short("H"))36 .arg(arg("no-ignore").long("no-ignore").short("I"))37 .arg(arg("rg-alias-hidden-ignore").short("u").multiple(true).hidden(true))38- .arg(arg("case-sensitive").long("case-sensitive").short("s"))38+ .arg(arg("case-sensitive").long("case-sensitive").short("s").overrides_with("ignore-case"))39+ .arg(arg("ignore-case").long("ignore-case").short("i").overrides_with("case-sensitive"))40 .arg(arg("absolute-path").long("absolute-path").short("a"))41 .arg(arg("follow").long("follow").short("L").alias("dereference"))42 .arg(arg("full-path").long("full-path").short("p"))43 .arg(arg("null_separator").long("print0").short("0"))54 unmodified lines98 doc!(h, "case-sensitive"99 , "Case-sensitive search (default: smart case)"100 , "Perform a case-sensitive search. By default, fd uses case-insensitive searches, \101 unless the pattern contains both upper- and lowercase characters (smart case).");102+ doc!(h, "ignore-case"103+ , "Case-insensitive search (default: smart case)"104+ , "Perform a case-insensitive search. By default, fd uses case-insensitive searches, \105+ unless the pattern contains both upper- and lowercase characters (smart case).");106 doc!(h, "absolute-path"107 , "Show absolute instead of relative paths"108 , "Shows the full path starting from the root as opposed to relative paths.");109 doc!(h, "follow"49 unmodified linesmodified:src/internal.rs+1 added-1 removed
22 unmodified lines23 }24 25 /// Configuration options for *fd*.26 pub struct FdOptions {27- /// Determines whether the regex search is case-sensitive or case-insensitive.27+ /// Whether the search is case-sensitive or case-insensitive.28 pub case_sensitive: bool,29 30 /// Whether to search within the full file path or just the base name (filename or directory31 /// name).49 unmodified linesmodified:src/main.rs+5 added-2 removed
60 unmodified lines61 let root_dir = root_dir_buf.as_path();62 63 // The search will be case-sensitive if the command line flag is set or64 // if the pattern has an uppercase character (smart case).65- let case_sensitive = matches.is_present("case-sensitive") ||66- pattern.chars().any(char::is_uppercase);65+ let case_sensitive = if !matches.is_present("ignore-case") {66+ matches.is_present("case-sensitive") || pattern.chars().any(char::is_uppercase)67+ } else {68+ false69+ };70 71 let colored_output = match matches.value_of("color") {72 Some("always") => true,73 Some("never") => false,62 unmodified linesmodified:tests/tests.rs+20 added
113 unmodified lines114 115 te.assert_output(116 &["--case-sensitive", "C.Foo"],117 "one/two/C.Foo2");118+119+ te.assert_output(120+ &["--ignore-case", "--case-sensitive", "C.Foo"],121+ "one/two/C.Foo2");122 }123 124+/// Case insensitivity (--ignore-case)125+#[test]126+fn test_case_insensitive() {127+ let te = TestEnv::new();128+129+ te.assert_output(130+ &["--ignore-case", "C.Foo"],131+ "one/two/c.foo132+ one/two/C.Foo2");133+134+ te.assert_output(135+ &["--case-sensitive", "--ignore-case", "C.Foo"],136+ "one/two/c.foo137+ one/two/C.Foo2");138+}139+140 /// Full path search (--full-path)141 #[test]142 fn test_full_path() {143 let te = TestEnv::new();228 unmodified lines