From 1fea5c81c408b9f5ff6487fc472c76a9633185fb Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 18 Apr 2026 09:06:51 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=84=20Update=20script=20metadata=20and?= =?UTF-8?q?=20add=20auto-hide=20feature=20in=20tree-rs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解释: - `script-meta-v2.json` 和 `script-meta.json` 文件中的脚本长度、SHA256 哈希值和更新时间被修改,表明脚本内容发生了变化。 - `tree-rs/src/main.rs` 中新增了 `--auto-hide` 参数及其逻辑,用于自动隐藏特定目录(如 `target`, `build`, `node_modules`),并对相关代码进行了调整。 - 这些变更主要涉及功能更新和元数据同步,因此用 🔄 表示更新。 --- script-meta-v2.json | 6 +++--- script-meta.json | 4 ++-- tree-rs/src/main.rs | 30 ++++++++++++++++++++++++------ 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/script-meta-v2.json b/script-meta-v2.json index fdec633..2a9ce8d 100644 --- a/script-meta-v2.json +++ b/script-meta-v2.json @@ -154,11 +154,11 @@ }, "tree.rs": { "script_name": "tree.rs", - "script_length": 5396, - "script_sha256": "9f4f662900f77016545552427d5cb0c45e211e51ccc37f9819d6be4f08fed364", + "script_length": 5878, + "script_sha256": "5bb247e793363bb839b535a1bacd6d52ad785b802b230fe20586048e298b7439", "script_full_url": "https://git.hatter.ink/rust-scripts/scriptbase/raw/branch/main/tree-rs/src/main.rs", "publish_time": 1776447368459, - "update_time": 1776447368459 + "update_time": 1776474400469 }, "xattr.rs": { "script_name": "xattr.rs", diff --git a/script-meta.json b/script-meta.json index 18872cf..0cd7f97 100644 --- a/script-meta.json +++ b/script-meta.json @@ -91,8 +91,8 @@ }, "tree-rs": { "script_name": "tree-rs", - "script_length": 5396, - "script_sha256": "9f4f662900f77016545552427d5cb0c45e211e51ccc37f9819d6be4f08fed364" + "script_length": 5878, + "script_sha256": "5bb247e793363bb839b535a1bacd6d52ad785b802b230fe20586048e298b7439" }, "xattr-rs": { "script_name": "xattr-rs", diff --git a/tree-rs/src/main.rs b/tree-rs/src/main.rs index 71c24a4..e5a25bf 100755 --- a/tree-rs/src/main.rs +++ b/tree-rs/src/main.rs @@ -30,6 +30,9 @@ struct Args { #[arg(long = "hide-dots", help = "Hide directories/files starting with a dot")] hide_dots: bool, + #[arg(short = 'A', long = "auto-hide", help = "Hide .*, target, build, node_modules")] + auto_hide: bool, + #[arg(long = "hide", help = "Hide entries matching this name")] hide: Vec, } @@ -43,6 +46,18 @@ fn main() { std::process::exit(1); } + let auto_hide_patterns: Vec = if args.auto_hide { + vec![ + "target".to_string(), + "build".to_string(), + "node_modules".to_string(), + ] + } else { + vec![] + }; + + let effective_hide_dots = args.hide_dots || args.auto_hide; + print_tree( &path, "", @@ -52,8 +67,8 @@ fn main() { args.depth, args.human_readable, args.no_color, - args.hide_dots, - args.hide.clone(), + effective_hide_dots, + auto_hide_patterns, ); } @@ -108,8 +123,11 @@ fn print_tree( let human_readable = human_readable; - let mut entries: Vec<_> = fs::read_dir(path) - .unwrap_or_else(|e| panic!("Failed to read directory {:?}: {}", path, e)) + let Ok(read_dir) = fs::read_dir(path) else { + eprintln!("Warning: Cannot read directory {:?}: Operation not permitted", path); + return; + }; + let mut entries: Vec<_> = read_dir .filter_map(|e| e.ok()) .filter(|e| { let binding = e.file_name(); @@ -204,5 +222,5 @@ fn format_size(bytes: u64, no_color: bool) -> String { } } -// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260418T013425+08:00.MEQCIBLXDlWGN9mmf8L/gXhw -// 92hRbs/GxAezQk646+N4Ho7OAiBAER2l2R1mPi00O51Ns00QIQN+WgAFD+RTyCnc8nbefw== +// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260418T090515+08:00.MEYCIQCr9lu4Bztm56IuzTv0 +// 11Egh7Qjmrfd3guWe70TIQhGzAIhAKaD5nY/hdLOKP06/o40saqscNmAKppvmv1kvBV631WU