Option to search hidden directories, closes #12
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by sharkdp · committed by sharkdp · parent 1986fc4 · Browse files · 1 file·+11 added−5 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+11 added−5 removed
- other:+11 added−5 removed
Provenance
- Commit
7076dcb- Tree
23a8f9a- Author
sharkdp <davidpeter@web.de>- Committer
sharkdp <davidpeter@web.de>- Parent
1986fc4
1 file changed+11 added−5 removed
modified:src/main.rs+11 added-5 removed
16 unmodified lines17 18 struct FdOptions {19 case_sensitive: bool,20 search_full_path: bool,21+ search_hidden: bool,22 follow_links: bool,23 colored: bool24 }25 24 unmodified lines50 fn scan(root: &Path, pattern: &Regex, config: &FdOptions) {51 let walker = WalkDir::new(root)52 .follow_links(config.follow_links)53 .into_iter()53- .filter_entry(|e| !is_hidden(e))54+ .filter_entry(|e| config.search_hidden || !is_hidden(e))55 .filter_map(|e| e.ok())56 .filter(|e| e.path() != root);57 58 for entry in walker {6 unmodified lines65 let res =66 if config.search_full_path {67 pattern.find(path_str)68 } else {69+ if !path_rel.is_file() { continue }70+71 path_rel.file_name()72 .and_then(OsStr::to_str)73 .and_then(|s| pattern.find(s))74 };18 unmodified lines93 opts.optflag("s", "sensitive",94 "case-sensitive search (default: smart case)");95 opts.optflag("f", "filename",96 "search filenames only (default: full path)");97+ opts.optflag("", "hidden",98+ "search hidden files/directories (default: off)");99 opts.optflag("F", "follow", "follow symlinks (default: off)");100 opts.optflag("n", "no-color", "do not colorize output");101 102 let matches = match opts.parse(&args[1..]) {19 unmodified lines122 123 let config = FdOptions {124 // The search will be case-sensitive if the command line flag is set or125 // if the pattern has an uppercase character (smart case).121- case_sensitive: matches.opt_present("s") ||126+ case_sensitive: matches.opt_present("sensitive") ||127 pattern.chars().any(char::is_uppercase),123- search_full_path: !matches.opt_present("f"),124- colored: !matches.opt_present("n"),125- follow_links: matches.opt_present("F")128+ search_full_path: !matches.opt_present("filename"),129+ search_hidden: matches.opt_present("hidden"),130+ colored: !matches.opt_present("no-color"),131+ follow_links: matches.opt_present("follow")132 };133 134 match RegexBuilder::new(pattern)135 .case_insensitive(!config.case_sensitive)5 unmodified lines