Skip to content
Myr

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

8 files+60 added−7 removed

modified:doc/fd.1+11 added-4 removed
31 unmodified lines
32.TP33.B \-I, \-\-no\-ignore34Show search results from files and directories that would otherwise be ignored by35.IR .gitignore ,36.I .ignore37or38.I .fdignore39files.36.IR .ignore ,37.IR .fdignore ,38or the global ignore file.39.TP40.B \-u, \-\-unrestricted41Alias for '--no-ignore'. Can be repeated; '-uu' is an alias for '--no-ignore --hidden'.42.TP
237 unmodified lines
280.TP281.B LS_COLORS282Determines how to colorize search results, see283.BR dircolors (1) .284.TP285.B XDG_CONFIG_HOME, HOME286Used to locate the global ignore file. If287.B XDG_CONFIG_HOME288is set, use289.IR $XDG_CONFIG_HOME/fd/ignore .290Otherwise, use291.IR $HOME/.config/fd/ignore .292.SH EXAMPLES293.TP294.RI "Find files and directories that match the pattern '" needle "':"295$ fd needle
11 unmodified lines
modified:src/app.rs+7 added-1 removed
28 unmodified lines
29 .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 lines
43 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 lines
modified:src/main.rs+3 added
292 unmodified lines
293 || 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: matches
114 unmodified lines
modified:src/options.rs+3 added
25 unmodified lines
2627 /// Whether to respect VCS ignore files (`.gitignore`, ..) or not.28 pub read_vcsignore: bool,2930 /// Whether to respect the global ignore file or not.31 pub read_global_ignore: bool,3233 /// Whether to follow symlinks or not.34 pub follow_links: bool,3536 /// Whether to limit the search to starting file system or not.
66 unmodified lines
modified:src/walk.rs+29 added
1use std::borrow::Cow;2use std::env;3use std::ffi::OsStr;4use std::fs::{FileType, Metadata};5use std::io;6use std::path::{Path, PathBuf};
75 unmodified lines
82 if config.read_fdignore {83 walker.add_custom_ignore_filename(".fdignore");84 }8586 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")));9293 #[cfg(not(target_os = "macos"))]94 let config_dir_op = dirs::config_dir();9596 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 }113114 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 lines
modified:tests/testenv/mod.rs+2 added-2 removed
188 unmodified lines
189 ) -> 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);194195 // Run *fd*.196 let output = cmd.output().expect("fd output");197
52 unmodified lines
250 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);255256 // Run *fd*.257 let output = cmd.output().expect("fd output");258
12 unmodified lines
modified:Cargo.toml+1 added
modified:README.md+4 added
456 unmodified lines
457*.bak458```459Note: `fd` also supports `.ignore` files that are used by other programs such as `rg` or `ag`.460461If you want `fd` to ignore these patterns globally, you can put them in `fd`'s global ignore file.462This is usually located in `~/.config/fd/ignore` in macOS or Linux, and `%APPDATA%\fd\ignore` in463Windows.464465### Using fd with `xargs` or `parallel`466467If we want to run a command on all search results, we can pipe the output to `xargs`:468``` bash
121 unmodified lines