Add global fdignore support
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Bobbie Soedirgo · committed by David Peter · parent a9dc45e · Browse files · 8 files·+60 added−7 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+60 added−7 removed
- tests:+2 added−2 removed
- other:+58 added−5 removed
Provenance
- Commit
79d5a5b- Tree
913f8e1- Author
Bobbie Soedirgo <bobbie@soedirgo.dev>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
a9dc45e
8 files changed+60 added−7 removed
modified:doc/fd.1+11 added-4 removed
31 unmodified lines32 .TP33 .B \-I, \-\-no\-ignore34 Show search results from files and directories that would otherwise be ignored by35 .IR .gitignore ,36-.I .ignore37-or38-.I .fdignore39-files.36+.IR .ignore ,37+.IR .fdignore ,38+or the global ignore file.39 .TP40 .B \-u, \-\-unrestricted41 Alias for '--no-ignore'. Can be repeated; '-uu' is an alias for '--no-ignore --hidden'.42 .TP237 unmodified lines280 .TP281 .B LS_COLORS282 Determines how to colorize search results, see283 .BR dircolors (1) .284+.TP285+.B XDG_CONFIG_HOME, HOME286+Used to locate the global ignore file. If287+.B XDG_CONFIG_HOME288+is set, use289+.IR $XDG_CONFIG_HOME/fd/ignore .290+Otherwise, use291+.IR $HOME/.config/fd/ignore .292 .SH EXAMPLES293 .TP294 .RI "Find files and directories that match the pattern '" needle "':"295 $ fd needle11 unmodified linesmodified:src/app.rs+7 added-1 removed
28 unmodified lines29 .overrides_with("no-ignore")30 .help("Do not respect .(git|fd)ignore files")31 .long_help(32 "Show search results from files and directories that would otherwise be \33- ignored by '.gitignore', '.ignore' or '.fdignore' files.",33+ ignored by '.gitignore', '.ignore', '.fdignore', or the global ignore file.",34 ),35 )36 .arg(37 Arg::with_name("no-ignore-vcs")5 unmodified lines43 ignored by '.gitignore' files.",44 ),45 )46 .arg(47+ Arg::with_name("no-global-ignore-file")48+ .long("no-global-ignore-file")49+ .hidden(true)50+ .long_help("Do not respect the global ignore file."),51+ )52+ .arg(53 Arg::with_name("rg-alias-hidden-ignore")54 .short("u")55 .long("unrestricted")56 .multiple(true)516 unmodified linesmodified:src/main.rs+3 added
292 unmodified lines293 || matches.is_present("rg-alias-hidden-ignore")),294 read_vcsignore: !(matches.is_present("no-ignore")295 || matches.is_present("rg-alias-hidden-ignore")296 || matches.is_present("no-ignore-vcs")),297+ read_global_ignore: !(matches.is_present("no-ignore")298+ || matches.is_present("rg-alias-hidden-ignore")299+ || matches.is_present("no-global-ignore-file")),300 follow_links: matches.is_present("follow"),301 one_file_system: matches.is_present("one-file-system"),302 null_separator: matches.is_present("null_separator"),303 max_depth: matches114 unmodified linesmodified:src/options.rs+3 added
25 unmodified lines26 27 /// Whether to respect VCS ignore files (`.gitignore`, ..) or not.28 pub read_vcsignore: bool,29 30+ /// Whether to respect the global ignore file or not.31+ pub read_global_ignore: bool,32+33 /// Whether to follow symlinks or not.34 pub follow_links: bool,35 36 /// Whether to limit the search to starting file system or not.66 unmodified linesmodified:src/walk.rs+29 added
1 use std::borrow::Cow;2+use std::env;3 use std::ffi::OsStr;4 use std::fs::{FileType, Metadata};5 use std::io;6 use std::path::{Path, PathBuf};75 unmodified lines82 if config.read_fdignore {83 walker.add_custom_ignore_filename(".fdignore");84 }85 86+ if config.read_global_ignore {87+ #[cfg(target_os = "macos")]88+ let config_dir_op = env::var_os("XDG_CONFIG_HOME")89+ .map(PathBuf::from)90+ .filter(|p| p.is_absolute())91+ .or_else(|| dirs::home_dir().map(|d| d.join(".config")));92+93+ #[cfg(not(target_os = "macos"))]94+ let config_dir_op = dirs::config_dir();95+96+ if let Some(global_ignore_file) = config_dir_op97+ .map(|p| p.join("fd").join("ignore"))98+ .filter(|p| p.is_file())99+ {100+ let result = walker.add_ignore(global_ignore_file);101+ match result {102+ Some(ignore::Error::Partial(_)) => (),103+ Some(err) => {104+ print_error(format!(105+ "Malformed pattern in global ignore file. {}.",106+ err.to_string()107+ ));108+ }109+ None => (),110+ }111+ }112+ }113+114 for ignore_file in &config.ignore_files {115 let result = walker.add_ignore(ignore_file);116 match result {117 Some(ignore::Error::Partial(_)) => (),384 unmodified linesmodified:tests/testenv/mod.rs+2 added-2 removed
188 unmodified lines189 ) -> process::Output {190 // Setup *fd* command.191 let mut cmd = process::Command::new(&self.fd_exe);192 cmd.current_dir(self.temp_dir.path().join(path));193- cmd.args(args);193+ cmd.arg("--no-global-ignore-file").args(args);194 195 // Run *fd*.196 let output = cmd.output().expect("fd output");197 52 unmodified lines250 fn assert_error_subdirectory<P: AsRef<Path>>(&self, path: P, args: &[&str], expected: &str) {251 // Setup *fd* command.252 let mut cmd = process::Command::new(&self.fd_exe);253 cmd.current_dir(self.temp_dir.path().join(path));254- cmd.args(args);254+ cmd.arg("--no-global-ignore-file").args(args);255 256 // Run *fd*.257 let output = cmd.output().expect("fd output");258 12 unmodified linesmodified:Cargo.toml+1 added
44 unmodified lines45464748495051525318 unmodified lines44 unmodified lineshumantime = "2.0"lscolors = "0.7"globset = "0.4"anyhow = "1.0"dirs = "2.0"
[dependencies.clap]version = "2.31.2"features = ["suggestions", "color", "wrap_help"]18 unmodified linesmodified:README.md+4 added
456 unmodified lines457 *.bak458 ```459 Note: `fd` also supports `.ignore` files that are used by other programs such as `rg` or `ag`.460 461+If you want `fd` to ignore these patterns globally, you can put them in `fd`'s global ignore file.462+This is usually located in `~/.config/fd/ignore` in macOS or Linux, and `%APPDATA%\fd\ignore` in463+Windows.464+465 ### Using fd with `xargs` or `parallel`466 467 If we want to run a command on all search results, we can pipe the output to `xargs`:468 ``` bash121 unmodified lines