From 2b00cae8e11d28ec67ac0e169f50462dceec0ced Mon Sep 17 00:00:00 2001 From: Carlos de Paula Date: Mon, 20 Oct 2025 11:02:29 -0300 Subject: [PATCH] Enhance context matching for exclude rules with wildcard support --- yazi-config/src/files/exclude.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/yazi-config/src/files/exclude.rs b/yazi-config/src/files/exclude.rs index 263c4884..c5818820 100644 --- a/yazi-config/src/files/exclude.rs +++ b/yazi-config/src/files/exclude.rs @@ -98,12 +98,29 @@ impl Exclude { return true; } - // Handle glob patterns + // Handle glob patterns with wildcard if self.context.ends_with("/**") { let prefix = &self.context[..self.context.len() - 3]; - path.starts_with(prefix) - } else { - path == self.context || path.starts_with(&format!("{}/", self.context)) + + // Check if path starts with prefix (absolute path match) + if path.starts_with(prefix) { + return true; + } + + // Check if path contains the pattern anywhere (for relative patterns like "/target/**") + // This allows "/target/**" to match "/home/user/project/target/debug" + if prefix.starts_with('/') && !prefix.starts_with("//") { + // Single leading slash means relative pattern - check if path contains this segment + let pattern = &prefix[1..]; // Remove leading slash + if path.contains(&format!("/{}/", pattern)) || path.ends_with(&format!("/{}", pattern)) { + return true; + } + } + + return false; } + + // Exact match or prefix match for non-wildcard patterns + path == self.context || path.starts_with(&format!("{}/", self.context)) } }