Skip to content
Myr

Match case-insensitive by default

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by sharkdp · committed by sharkdp · parent 12bfee0 · Browse files · 1 file+9 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+9 added−2 removed

  • other:+9 added−2 removed

1 file+9 added−2 removed

modified:src/main.rs+9 added-2 removed
7 unmodified lines
8use std::process;9use std::error::Error;1011use walkdir::{WalkDir, DirEntry, WalkDirIterator};12use regex::Regex;12use regex::{Regex, RegexBuilder};13use getopts::Options;1415/// Check if filename of entry starts with a dot.16fn is_hidden(entry: &DirEntry) -> bool {17 entry.file_name()18 .to_str()19 .map(|s| s.starts_with("."))20 .unwrap_or(false)21}2223/// Recursively scan the given root path and search for pathnames matching the24/// pattern.25fn scan(root: &Path, pattern: &Regex) {26 let walker = WalkDir::new(root).into_iter();27 for entry in walker.filter_entry(|e| !is_hidden(e))28 .filter_map(|e| e.ok()) {
14 unmodified lines
43 }44 }45}4647/// Print error message to stderr and exit with status `1`.48fn error<T: Error>(err: &T) -> ! {49 writeln!(&mut std::io::stderr(), "{}", err.description())50 .expect("Failed writing to stderr");51 process::exit(1);
21 unmodified lines
73 let current_dir_buf = env::current_dir()74 .expect("Could not get current directory!");75 let current_dir = current_dir_buf.as_path();7673 match Regex::new(pattern) {77 match78 RegexBuilder::new(pattern)79 .case_insensitive(true)80 .build() {81 Ok(re) =>82 scan(current_dir, &re),83 Err(err) => error(&err)84 }
1 unmodified line