mirror of https://github.com/sharkdp/fd.git
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*'`.
|
* Easy syntax: `fd PATTERN` instead of `find -iname '*PATTERN*'`.
|
||||||
* Colored output.
|
* Colored output.
|
||||||
* Regular expressions.
|
* 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` :-).
|
* The command name is *50%* shorter than `find` :-).
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -82,8 +82,6 @@ fn main() {
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let case_insensitive = !matches.opt_present("s");
|
|
||||||
|
|
||||||
let empty = String::new();
|
let empty = String::new();
|
||||||
let pattern = matches.free.get(0).unwrap_or(&empty);
|
let pattern = matches.free.get(0).unwrap_or(&empty);
|
||||||
|
|
||||||
|
@ -93,8 +91,14 @@ fn main() {
|
||||||
};
|
};
|
||||||
let current_dir = current_dir_buf.as_path();
|
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)
|
match RegexBuilder::new(pattern)
|
||||||
.case_insensitive(case_insensitive)
|
.case_insensitive(!case_sensitive)
|
||||||
.build() {
|
.build() {
|
||||||
Ok(re) => scan(current_dir, &re),
|
Ok(re) => scan(current_dir, &re),
|
||||||
Err(err) => error(err.description())
|
Err(err) => error(err.description())
|
||||||
|
|
Loading…
Reference in New Issue