Skip to content
Myr

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

1 file+11 added−5 removed

modified:src/main.rs+11 added-5 removed
16 unmodified lines
1718struct FdOptions {19 case_sensitive: bool,20 search_full_path: bool,21 search_hidden: bool,22 follow_links: bool,23 colored: bool24}25
24 unmodified lines
50fn 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);5758 for entry in walker {
6 unmodified lines
65 let res =66 if config.search_full_path {67 pattern.find(path_str)68 } else {69 if !path_rel.is_file() { continue }7071 path_rel.file_name()72 .and_then(OsStr::to_str)73 .and_then(|s| pattern.find(s))74 };
18 unmodified lines
93 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");101102 let matches = match opts.parse(&args[1..]) {
19 unmodified lines
122123 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 };133134 match RegexBuilder::new(pattern)135 .case_insensitive(!config.case_sensitive)
5 unmodified lines