Skip to content
Myr

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

3 files+78 added−31 removed

modified:src/main.rs+23 added-29 removed
1extern crate ansi_term;2extern crate getopts;3extern crate isatty;4extern crate regex;5extern crate walkdir;5extern crate ignore;67use std::collections::HashMap;8use std::env;9use std::error::Error;
6 unmodified lines
16use ansi_term::{Style, Colour};17use getopts::Options;18use isatty::stdout_isatty;19use regex::{Regex, RegexBuilder};20use walkdir::{WalkDir, DirEntry, WalkDirIterator};20use ignore::WalkBuilder;2122/// Maps file extensions to ANSI colors / styles.23type ExtensionStyles = HashMap<String, ansi_term::Style>;2425/// Configuration options for *fd*.26struct 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}3636/// The default maximum recursion depth.37const MAX_DEPTH_DEFAULT : usize = 25;3837/// Print a search result to the console.38fn print_entry(path_root: &Path, path_entry: &Path, config: &FdOptions) {39 let path_full = path_root.join(path_entry);40
47 unmodified lines
88 println!();89 }90}9194/// Check if filename of entry starts with a dot.95fn is_hidden(entry: &DirEntry) -> bool {96 entry.file_name()97 .to_str()98 .map(|s| s.starts_with("."))99 .unwrap_or(false)100}10192/// Recursively scan the given root path and search for files / pathnames93/// matching the pattern.94fn 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);108109 for entry in walker {
89 unmodified lines
199 "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");212213 let matches = match opts.parse(&args[1..]) {214 Ok(m) => m,215 Err(e) => error(e.description())
31 unmodified lines
247 // 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 };260261 match RegexBuilder::new(pattern)
6 unmodified lines
modified:Cargo.lock+54 added-1 removed
2 unmodified lines
3version = "0.3.0"4dependencies = [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]1112[[package]]13name = "aho-corasick"
8 unmodified lines
22version = "0.9.0"23source = "registry+https://github.com/rust-lang/crates.io-index"2425[[package]]26name = "crossbeam"27version = "0.2.10"28source = "registry+https://github.com/rust-lang/crates.io-index"2930[[package]]31name = "fnv"32version = "1.0.5"33source = "registry+https://github.com/rust-lang/crates.io-index"3435[[package]]36name = "getopts"37version = "0.2.14"38source = "registry+https://github.com/rust-lang/crates.io-index"3940[[package]]41name = "globset"42version = "0.2.0"43source = "registry+https://github.com/rust-lang/crates.io-index"44dependencies = [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]5152[[package]]53name = "ignore"54version = "0.2.0"55source = "registry+https://github.com/rust-lang/crates.io-index"56dependencies = [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]6667[[package]]68name = "isatty"69version = "0.1.3"70source = "registry+https://github.com/rust-lang/crates.io-index"71dependencies = [
11 unmodified lines
83 "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",84]8586[[package]]87name = "lazy_static"88version = "0.2.8"89source = "registry+https://github.com/rust-lang/crates.io-index"9091[[package]]92name = "libc"93version = "0.2.22"94source = "registry+https://github.com/rust-lang/crates.io-index"9596[[package]]97name = "log"98version = "0.3.7"99source = "registry+https://github.com/rust-lang/crates.io-index"100101[[package]]102name = "memchr"103version = "1.0.1"104source = "registry+https://github.com/rust-lang/crates.io-index"105dependencies = [
84 unmodified lines
190191[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 lines
modified:Cargo.toml+1 added-1 removed