mirror of
https://github.com/sharkdp/fd.git
synced 2026-08-31 01:15:43 +08:00
--ignore-contain: ignore directories containing a named entry (e.g. [CACHEDIR.TAG](https://bford.info/cachedir/)).
Fixes #1727.
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
||||
# Upcoming release
|
||||
|
||||
## Features
|
||||
|
||||
- Add `--ignore-contain` option to ignore directories containing a named entry (e.g. to ignore [`CACHEDIR.TAG`](https://bford.info/cachedir/)); see #1727 (@fischman).
|
||||
|
||||
## Bugfixes
|
||||
|
||||
|
||||
+10
@@ -528,6 +528,16 @@ pub struct Opts {
|
||||
)]
|
||||
pub hyperlink: HyperlinkWhen,
|
||||
|
||||
/// Ignore directories containing the named entry.
|
||||
#[arg(
|
||||
long,
|
||||
value_name = "name",
|
||||
hide_short_help = true,
|
||||
help = "Ignore directories containing this name",
|
||||
long_help
|
||||
)]
|
||||
pub ignore_contain: Option<String>,
|
||||
|
||||
/// Set number of threads to use for searching & executing (default: number
|
||||
/// of available CPU cores)
|
||||
#[arg(long, short = 'j', value_name = "num", hide_short_help = true, value_parser = str::parse::<NonZeroUsize>)]
|
||||
|
||||
@@ -130,6 +130,9 @@ pub struct Config {
|
||||
|
||||
/// Whether or not to use hyperlinks on paths
|
||||
pub hyperlink: bool,
|
||||
|
||||
/// A name that should stop traversal down its parent. (e.g. https://bford.info/cachedir/).
|
||||
pub ignore_contain: Option<String>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
|
||||
@@ -326,6 +326,7 @@ fn construct_config(mut opts: Opts, pattern_regexps: &[String]) -> Result<Config
|
||||
actual_path_separator,
|
||||
max_results: opts.max_results(),
|
||||
strip_cwd_prefix: opts.strip_cwd_prefix(|| !(opts.null_separator || has_command)),
|
||||
ignore_contain: opts.ignore_contain,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -560,6 +560,14 @@ impl WorkerState {
|
||||
}
|
||||
}
|
||||
|
||||
// Filter out directories containing a given name.
|
||||
if let Some(ref ignore_contain) = config.ignore_contain
|
||||
&& entry_path.is_dir()
|
||||
&& entry_path.join(ignore_contain).exists()
|
||||
{
|
||||
return WalkState::Skip;
|
||||
}
|
||||
|
||||
// Filter out unwanted sizes if it is a file and we have been given size constraints.
|
||||
if !config.size_constraints.is_empty() {
|
||||
if entry_path.is_file() {
|
||||
|
||||
@@ -2707,3 +2707,21 @@ fn test_hyperlink() {
|
||||
|
||||
te.assert_output(&["--hyperlink=always", "a.foo"], &expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ignore_contain() {
|
||||
let te = TestEnv::new(
|
||||
&["include", "exclude", "exclude/sub"],
|
||||
&[
|
||||
"top",
|
||||
"include/foo",
|
||||
"exclude/CACHEDIR.TAG",
|
||||
"exclude/sub/nope",
|
||||
],
|
||||
);
|
||||
let expected = "include/
|
||||
include/foo
|
||||
symlink
|
||||
top";
|
||||
te.assert_output(&["--ignore-contain=CACHEDIR.TAG", "."], expected);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user