mirror of
https://github.com/sharkdp/fd
synced 2024-10-04 14:59:15 +00:00
Implement smart-case, closes #7
This commit is contained in:
parent
fba5e02c25
commit
6482f3ac09
|
@ -5,6 +5,8 @@ A modern, convenient and fast replacement for `find`.
|
|||
* Easy syntax: `fd PATTERN` instead of `find -iname '*PATTERN*'`.
|
||||
* Colored output.
|
||||
* Regular expressions.
|
||||
* Smart case: the search is case-insensitive by default, but will be
|
||||
case-sensitive if the pattern contains an uppercase character.
|
||||
* The command name is *50%* shorter than `find` :-).
|
||||
|
||||
## Examples
|
||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -82,8 +82,6 @@ fn main() {
|
|||
process::exit(1);
|
||||
}
|
||||
|
||||
let case_insensitive = !matches.opt_present("s");
|
||||
|
||||
let empty = String::new();
|
||||
let pattern = matches.free.get(0).unwrap_or(&empty);
|
||||
|
||||
|
@ -93,8 +91,14 @@ fn main() {
|
|||
};
|
||||
let current_dir = current_dir_buf.as_path();
|
||||
|
||||
// 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.opt_present("s") ||
|
||||
pattern.chars().any(char::is_uppercase);
|
||||
|
||||
match RegexBuilder::new(pattern)
|
||||
.case_insensitive(case_insensitive)
|
||||
.case_insensitive(!case_sensitive)
|
||||
.build() {
|
||||
Ok(re) => scan(current_dir, &re),
|
||||
Err(err) => error(err.description())
|
||||
|
|
Loading…
Reference in a new issue