mirror of https://github.com/sharkdp/fd.git
Match case-insensitive by default
This commit is contained in:
parent
12bfee0bec
commit
2b9db47474
11
src/main.rs
11
src/main.rs
|
@ -9,9 +9,10 @@ use std::process;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
use walkdir::{WalkDir, DirEntry, WalkDirIterator};
|
use walkdir::{WalkDir, DirEntry, WalkDirIterator};
|
||||||
use regex::Regex;
|
use regex::{Regex, RegexBuilder};
|
||||||
use getopts::Options;
|
use getopts::Options;
|
||||||
|
|
||||||
|
/// Check if filename of entry starts with a dot.
|
||||||
fn is_hidden(entry: &DirEntry) -> bool {
|
fn is_hidden(entry: &DirEntry) -> bool {
|
||||||
entry.file_name()
|
entry.file_name()
|
||||||
.to_str()
|
.to_str()
|
||||||
|
@ -19,6 +20,8 @@ fn is_hidden(entry: &DirEntry) -> bool {
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Recursively scan the given root path and search for pathnames matching the
|
||||||
|
/// pattern.
|
||||||
fn scan(root: &Path, pattern: &Regex) {
|
fn scan(root: &Path, pattern: &Regex) {
|
||||||
let walker = WalkDir::new(root).into_iter();
|
let walker = WalkDir::new(root).into_iter();
|
||||||
for entry in walker.filter_entry(|e| !is_hidden(e))
|
for entry in walker.filter_entry(|e| !is_hidden(e))
|
||||||
|
@ -41,6 +44,7 @@ fn scan(root: &Path, pattern: &Regex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Print error message to stderr and exit with status `1`.
|
||||||
fn error<T: Error>(err: &T) -> ! {
|
fn error<T: Error>(err: &T) -> ! {
|
||||||
writeln!(&mut std::io::stderr(), "{}", err.description())
|
writeln!(&mut std::io::stderr(), "{}", err.description())
|
||||||
.expect("Failed writing to stderr");
|
.expect("Failed writing to stderr");
|
||||||
|
@ -70,7 +74,10 @@ fn main() {
|
||||||
.expect("Could not get current directory!");
|
.expect("Could not get current directory!");
|
||||||
let current_dir = current_dir_buf.as_path();
|
let current_dir = current_dir_buf.as_path();
|
||||||
|
|
||||||
match Regex::new(pattern) {
|
match
|
||||||
|
RegexBuilder::new(pattern)
|
||||||
|
.case_insensitive(true)
|
||||||
|
.build() {
|
||||||
Ok(re) =>
|
Ok(re) =>
|
||||||
scan(current_dir, &re),
|
scan(current_dir, &re),
|
||||||
Err(err) => error(&err)
|
Err(err) => error(&err)
|
||||||
|
|
Loading…
Reference in New Issue