From 2fdd7b6f554dd4e15648ed8f611bd83cedd511c8 Mon Sep 17 00:00:00 2001 From: tlss Date: Mon, 23 Dec 2024 18:55:26 +0800 Subject: [PATCH] feat: hide specified files and dirs --- Cargo.lock | 25 +++++++++++++------------ yazi-config/src/manager/manager.rs | 1 + yazi-shared/Cargo.toml | 2 ++ yazi-shared/src/url/urn.rs | 7 ++++++- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a22c8c928..5d147bf40 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -117,9 +117,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.94" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7" +checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" [[package]] name = "arbitrary" @@ -294,9 +294,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.20.0" +version = "1.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b37c88a63ffd85d15b406896cc343916d7cf57838a847b3a6f2ca5d39a5695a" +checksum = "ef657dfab802224e671f5818e9a4935f9b1957ed18e58292690cc39e7a4092a3" [[package]] name = "byteorder" @@ -1282,9 +1282,9 @@ dependencies = [ [[package]] name = "instability" -version = "0.3.3" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b829f37dead9dc39df40c2d3376c179fdfd2ac771f53f55d3c30dc096a3c0c6e" +checksum = "898e106451f7335950c9cc64f8ec67b5f65698679ac67ed00619aeef14e1cf75" dependencies = [ "darling", "indoc", @@ -1758,9 +1758,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.5" +version = "0.36.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" +checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" dependencies = [ "memchr", ] @@ -2286,9 +2286,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.133" +version = "1.0.134" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" +checksum = "d00f4175c42ee48b15416f6193a959ba3a0d67fc699a0db9ad12df9f83991c7d" dependencies = [ "itoa", "memchr", @@ -2456,9 +2456,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.90" +version = "2.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" +checksum = "d53cbcb5a243bd33b7858b1d7f4aca2153490815872d86d955d6ea29f743c035" dependencies = [ "proc-macro2", "quote", @@ -3625,6 +3625,7 @@ dependencies = [ "parking_lot", "percent-encoding", "ratatui", + "regex", "serde", "shell-words", "tokio", diff --git a/yazi-config/src/manager/manager.rs b/yazi-config/src/manager/manager.rs index 42e0171dd..633d462bd 100644 --- a/yazi-config/src/manager/manager.rs +++ b/yazi-config/src/manager/manager.rs @@ -26,6 +26,7 @@ pub struct Manager { pub scrolloff: u8, pub mouse_events: MouseEvents, pub title_format: String, + pub hidden_rule: String, // TODO: remove this in Yazi 0.4.2 #[serde(default)] diff --git a/yazi-shared/Cargo.toml b/yazi-shared/Cargo.toml index 2e4281af6..d5aaad104 100644 --- a/yazi-shared/Cargo.toml +++ b/yazi-shared/Cargo.toml @@ -11,6 +11,7 @@ rust-version = "1.78.0" [dependencies] yazi-macro = { path = "../yazi-macro", version = "0.4.3" } +yazi-config = { path = "../yazi-config", version = "0.4.3" } # External dependencies anyhow = { workspace = true } @@ -22,6 +23,7 @@ ratatui = { workspace = true } serde = { workspace = true } shell-words = { workspace = true } tokio = { workspace = true } +regex = { workspace = true } [target."cfg(unix)".dependencies] libc = { workspace = true } diff --git a/yazi-shared/src/url/urn.rs b/yazi-shared/src/url/urn.rs index 57104539d..f7a488870 100644 --- a/yazi-shared/src/url/urn.rs +++ b/yazi-shared/src/url/urn.rs @@ -1,4 +1,7 @@ use std::{borrow::{Borrow, Cow}, ffi::OsStr, ops::Deref, path::{Path, PathBuf}}; +use regex::Regex; + +use yazi_config::MANAGER; #[derive(Debug, Eq, PartialEq, Hash)] #[repr(transparent)] @@ -16,7 +19,9 @@ impl Urn { #[cfg(unix)] #[inline] pub fn is_hidden(&self) -> bool { - self.name().is_some_and(|s| s.as_encoded_bytes().starts_with(b".")) + // let re = Regex::new(r"^\.|^lost\+found$").unwrap(); + let re = Regex::new(MANAGER.hidden_rule).unwrap(); + self.name().is_some_and(|s| re.is_match(&String::from_utf8_lossy(s.as_encoded_bytes()))) } }