Skip to content
Myr

--filename instead of --full-path

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

authored by sharkdp · committed by sharkdp · parent e20bd9d · Browse files · 1 file+25 added−19 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+25 added−19 removed

  • other:+25 added−19 removed

1 file+25 added−19 removed

modified:src/main.rs+25 added-19 removed
53 unmodified lines
54 .filter_map(|e| e.ok())55 .filter(|e| e.path() != root);5657 for entry in walker {58 if let Ok(path_relative) = entry.path().strip_prefix(root) {59 if let Some(path_str) = path_relative.to_str() {60 let haystack = if config.search_full_path {61 path_str62 } else {63 path_relative.file_name()64 .and_then(OsStr::to_str)65 .unwrap()66 };67 pattern.find(haystack)68 .map(|_| print_entry(&entry, path_str, &config));69 }58 let path_rel = match entry.path().strip_prefix(root) {59 Ok(p) => p,60 Err(_) => continue61 };6263 if let Some(path_str) = path_rel.to_str() {64 let res =65 if config.search_full_path {66 pattern.find(path_str)67 } else {68 path_rel.file_name()69 .and_then(OsStr::to_str)70 .and_then(|s| pattern.find(s))71 };7273 res.map(|_| print_entry(&entry, path_str, &config));74 }75 }76}77
8 unmodified lines
86 let args: Vec<String> = env::args().collect();8788 let mut opts = Options::new();89 opts.optflag("h", "help", "print this help message");86 opts.optflag("s", "sensitive", "case-sensitive search (default: smart case)");87 opts.optflag("f", "full-path", "search full path (default: only filename)");90 opts.optflag("s", "sensitive",91 "case-sensitive search (default: smart case)");92 opts.optflag("f", "filename",93 "search filenames only (default: full path)");94 opts.optflag("F", "follow", "follow symlinks (default: off)");95 opts.optflag("n", "no-color", "do not colorize output");9697 let matches = match opts.parse(&args[1..]) {92 Ok(m) => m,98 Ok(m) => m,99 Err(e) => error(e.description())100 };101102 if matches.opt_present("h") {
12 unmodified lines
115 let current_dir = current_dir_buf.as_path();116117118 let config = FdOptions {113 // The search will be case-sensitive if the command line flag is set or if114 // the pattern has an uppercase character (smart case).119 // The search will be case-sensitive if the command line flag is set or120 // if the pattern has an uppercase character (smart case).121 case_sensitive: matches.opt_present("s") ||122 pattern.chars().any(char::is_uppercase),117 search_full_path: matches.opt_present("f"),123 search_full_path: !matches.opt_present("f"),124 colored: !matches.opt_present("n"),125 follow_links: matches.opt_present("F")126 };127128 match RegexBuilder::new(pattern)129 .case_insensitive(!config.case_sensitive)130 .build() {125 Ok(re) => scan(&current_dir, &re, &config),131 Ok(re) => scan(&current_dir, &re, &config),132 Err(err) => error(err.description())133 }134}