Switch to 'ignore', closes #4
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by sharkdp · committed by sharkdp · parent b18eded · Browse files · 3 files·+78 added−31 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+78 added−31 removed
- other:+78 added−31 removed
Provenance
- Commit
ae12e00- Tree
ef95c3b- Author
sharkdp <davidpeter@web.de>- Committer
sharkdp <davidpeter@web.de>- Parent
b18eded
3 files changed+78 added−31 removed
modified:src/main.rs+23 added-29 removed
1 extern crate ansi_term;2 extern crate getopts;3 extern crate isatty;4 extern crate regex;5-extern crate walkdir;5+extern crate ignore;6 7 use std::collections::HashMap;8 use std::env;9 use std::error::Error;6 unmodified lines16 use ansi_term::{Style, Colour};17 use getopts::Options;18 use isatty::stdout_isatty;19 use regex::{Regex, RegexBuilder};20-use walkdir::{WalkDir, DirEntry, WalkDirIterator};20+use ignore::WalkBuilder;21 22 /// Maps file extensions to ANSI colors / styles.23 type ExtensionStyles = HashMap<String, ansi_term::Style>;24 25 /// Configuration options for *fd*.26 struct FdOptions {27 case_sensitive: bool,28 search_full_path: bool,29- search_hidden: bool,29+ ignore_hidden: bool,30+ read_ignore: bool,31 follow_links: bool,32+ max_depth: Option<usize>,33 colored: bool,32- max_depth: usize,34 extension_styles: Option<ExtensionStyles>35 }36 36-/// The default maximum recursion depth.37-const MAX_DEPTH_DEFAULT : usize = 25;38-37 /// Print a search result to the console.38 fn print_entry(path_root: &Path, path_entry: &Path, config: &FdOptions) {39 let path_full = path_root.join(path_entry);40 47 unmodified lines88 println!();89 }90 }91 94-/// Check if filename of entry starts with a dot.95-fn is_hidden(entry: &DirEntry) -> bool {96- entry.file_name()97- .to_str()98- .map(|s| s.starts_with("."))99- .unwrap_or(false)100-}101-92 /// Recursively scan the given root path and search for files / pathnames93 /// matching the pattern.94 fn scan(root: &Path, pattern: &Regex, config: &FdOptions) {105- let walker = WalkDir::new(root)95+ let walker = WalkBuilder::new(root)96+ .hidden(config.ignore_hidden)97+ .ignore(config.read_ignore)98+ .git_ignore(config.read_ignore)99+ .parents(config.read_ignore)100+ .git_global(config.read_ignore)101+ .git_exclude(config.read_ignore)102 .follow_links(config.follow_links)103 .max_depth(config.max_depth)104+ .build()105 .into_iter()109- .filter_entry(|e| config.search_hidden110- || !is_hidden(e)111- || e.path() == root)106 .filter_map(|e| e.ok())107 .filter(|e| e.path() != root);108 109 for entry in walker {89 unmodified lines199 "case-sensitive search (default: smart case)");200 opts.optflag("p", "full-path",201 "search full path (default: filename only)");202 opts.optflag("H", "hidden",209- "search hidden files/directories (default: off)");203+ "search hidden files/directories");204+ opts.optflag("I", "no-ignore",205+ "do not respect .(git)ignore files");206 opts.optflag("f", "follow",211- "follow symlinks (default: off)");207+ "follow symlinks");208 opts.optflag("n", "no-color",213- "do not colorize output (default: on)");209+ "do not colorize output");210 opts.optopt( "d", "max-depth",215- format!("maximum search depth (default: {})",216- MAX_DEPTH_DEFAULT).as_str(),217- "D");211+ "maximum search depth (default: none)", "D");212 213 let matches = match opts.parse(&args[1..]) {214 Ok(m) => m,215 Err(e) => error(e.description())31 unmodified lines247 // if the pattern has an uppercase character (smart case).248 case_sensitive: matches.opt_present("sensitive") ||249 pattern.chars().any(char::is_uppercase),250 search_full_path: matches.opt_present("full-path"),257- search_hidden: matches.opt_present("hidden"),258- colored: colored_output,251+ ignore_hidden: !matches.opt_present("hidden"),252+ read_ignore: !matches.opt_present("no-ignore"),253 follow_links: matches.opt_present("follow"),254 max_depth:255 matches.opt_str("max-depth")262- .and_then(|ds| usize::from_str_radix(&ds, 10).ok())263- .unwrap_or(MAX_DEPTH_DEFAULT),256+ .and_then(|ds| usize::from_str_radix(&ds, 10).ok()),257+ colored: colored_output,258 extension_styles: ext_styles259 };260 261 match RegexBuilder::new(pattern)6 unmodified linesmodified:Cargo.lock+54 added-1 removed
2 unmodified lines3 version = "0.3.0"4 dependencies = [5 "ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",6 "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",7+ "ignore 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",8 "isatty 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",9 "regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",9- "walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",10 ]11 12 [[package]]13 name = "aho-corasick"8 unmodified lines22 version = "0.9.0"23 source = "registry+https://github.com/rust-lang/crates.io-index"24 25 [[package]]26+name = "crossbeam"27+version = "0.2.10"28+source = "registry+https://github.com/rust-lang/crates.io-index"29+30+[[package]]31+name = "fnv"32+version = "1.0.5"33+source = "registry+https://github.com/rust-lang/crates.io-index"34+35+[[package]]36 name = "getopts"37 version = "0.2.14"38 source = "registry+https://github.com/rust-lang/crates.io-index"39 40 [[package]]41+name = "globset"42+version = "0.2.0"43+source = "registry+https://github.com/rust-lang/crates.io-index"44+dependencies = [45+ "aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",46+ "fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",47+ "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",48+ "memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",49+ "regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",50+]51+52+[[package]]53+name = "ignore"54+version = "0.2.0"55+source = "registry+https://github.com/rust-lang/crates.io-index"56+dependencies = [57+ "crossbeam 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",58+ "globset 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",59+ "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",60+ "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",61+ "memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",62+ "regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",63+ "thread_local 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",64+ "walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",65+]66+67+[[package]]68 name = "isatty"69 version = "0.1.3"70 source = "registry+https://github.com/rust-lang/crates.io-index"71 dependencies = [11 unmodified lines83 "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",84 ]85 86 [[package]]87+name = "lazy_static"88+version = "0.2.8"89+source = "registry+https://github.com/rust-lang/crates.io-index"90+91+[[package]]92 name = "libc"93 version = "0.2.22"94 source = "registry+https://github.com/rust-lang/crates.io-index"95 96 [[package]]97+name = "log"98+version = "0.3.7"99+source = "registry+https://github.com/rust-lang/crates.io-index"100+101+[[package]]102 name = "memchr"103 version = "1.0.1"104 source = "registry+https://github.com/rust-lang/crates.io-index"105 dependencies = [84 unmodified lines190 191 [metadata]192 "checksum aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "500909c4f87a9e52355b26626d890833e9e1d53ac566db76c36faa984b889699"193 "checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6"194+"checksum crossbeam 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0c5ea215664ca264da8a9d9c3be80d2eaf30923c259d03e870388eb927508f97"195+"checksum fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6cc484842f1e2884faf56f529f960cc12ad8c71ce96cc7abba0a067c98fee344"196 "checksum getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9047cfbd08a437050b363d35ef160452c5fe8ea5187ae0a624708c91581d685"197+"checksum globset 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "feeb1b6840809ef5efcf7a4a990bc4e1b7ee3df8cf9e2379a75aeb2ba42ac9c3"198+"checksum ignore 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9bda0eaa44a060e21581315efb449e7fabceb93cf38c8376dd1b7e0623e07844"199 "checksum isatty 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "fa500db770a99afe2a0f2229be2a3d09c7ed9d7e4e8440bf71253141994e240f"200 "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"201+"checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf"202 "checksum libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)" = "babb8281da88cba992fa1f4ddec7d63ed96280a1a53ec9b919fd37b53d71e502"203+"checksum log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "5141eca02775a762cc6cd564d8d2c50f67c0ea3a372cbf1c51592b3e029e10ad"204 "checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4"205 "checksum regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4278c17d0f6d62dfef0ab00028feb45bd7d2102843f80763474eeb1be8a10c01"206 "checksum regex-syntax 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9191b1f57603095f105d317e375d19b1c9c5c3185ea9633a99a6dcbed04457"207 "checksum same-file 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d931a44fdaa43b8637009e7632a02adc4f2b2e0733c08caa4cf00e8da4a117a7"8 unmodified linesmodified:Cargo.toml+1 added-1 removed
6 unmodified lines7891011116 unmodified linesansi_term = "0.9"getopts = "0.2"isatty = "0.1"regex = "0.2"walkdir = "1"ignore = "0.2"