From 6b95d821f622a8c5438ee5142abb28f90aae7ed5 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 11 Apr 2026 09:43:20 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20Add=20hideFileSize=20optio?= =?UTF-8?q?n=20and=20update=20tree.ts=20script=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script-meta-v2.json | 6 +++--- single-scripts/tree.ts | 43 ++++++++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/script-meta-v2.json b/script-meta-v2.json index 46c73ee..55bc5be 100644 --- a/script-meta-v2.json +++ b/script-meta-v2.json @@ -322,12 +322,12 @@ }, "tree.ts": { "script_name": "tree.ts", - "script_length": 3356, - "script_sha256": "2ee61941b71b6b569d2ddd4fdbe62fe8fb40a6fe430f2a998b194aa8e9433cd4", + "script_length": 3482, + "script_sha256": "32984b9894f13b4717876d8843418b14cefcab289b19c9ed663cd3ba43ea7fa3", "script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/tree.ts", "single_script_file": true, "publish_time": 1769361581018, - "update_time": 1775871068962 + "update_time": 1775871788834 }, "trim.ts": { "script_name": "trim.ts", diff --git a/single-scripts/tree.ts b/single-scripts/tree.ts index 77bc3ca..a82cf92 100755 --- a/single-scripts/tree.ts +++ b/single-scripts/tree.ts @@ -22,6 +22,7 @@ const defaultSkipDirs = [ interface ListDirOptions { maxDepth: number; hideMoreDirs: boolean; + hideFileSize: boolean; } async function listDir( @@ -38,19 +39,17 @@ async function listDir( const fullName = joinPath(dir, dirEntry.name); if (dirEntry.isDirectory) { const showNextDepth = (depth + 1) <= options.maxDepth; - if (!options.hideMoreDirs) { - console.log( - `${tab}- [${dirEntry.name}]${ - showNextDepth - ? "" - : term.auto( - "[blue][[[ \t[...more dirs...]]]][/]", - ) - }`, - ); - } + console.log( + `${tab}- [${dirEntry.name}]${ + showNextDepth + ? "" + : (options.hideMoreDirs ? "" : term.auto( + "[blue][[[ \t[...more dirs...]]]][/]", + )) + }`, + ); if (showNextDepth) { - await listDir(fullName, depth + 1, options.maxDepth); + await listDir(fullName, depth + 1, options); } } else { let fileDesc = ""; @@ -68,11 +67,13 @@ async function listDir( ); } } - console.log( - `${tab}- ${ - term.auto("[green][[[" + dirEntry.name + "]]][/]") - } \t${fileDesc}`, - ); + let fileLn = `${tab}- ${ + term.auto("[green][[[" + dirEntry.name + "]]][/]") + }`; + if (!options.hideFileSize) { + fileLn += ` \t${fileDesc}`; + } + console.log(fileLn); } } } catch (e) { @@ -82,7 +83,7 @@ async function listDir( async function main(): Promise { const flags = parseArgs(Deno.args, { - boolean: ["help", "hide-more-dirs"], + boolean: ["help", "hide-more-dirs", "hide-file-size"], number: ["depth"], }); if (flags.help) { @@ -98,6 +99,7 @@ tree.ts [parameters] const maxDepth = parseIntVal(flags.depth, 10); const hideMoreDirs = flags["hide-more-dirs"]; + const hideFileSize = flags["hide-file-size"]; let baseDir = "."; if (flags._.length > 0) { @@ -106,10 +108,11 @@ tree.ts [parameters] await listDir(baseDir, 0, { maxDepth, hideMoreDirs, + hideFileSize, }); } main().catch((e) => log.error(e)); -// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260411T093048+08:00.MEUCIQDmZojbZR+wufhjkUbn -// UpciHPInFK+T7/F4u1pYzmfuOQIgOLnp7oKSmRQOqHo3XvP+wzZYMLAMAHanA+Q5iuODPLQ= +// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260411T094252+08:00.MEUCIFfZBs0de3SZZtVCpAZ6 +// Kxb5dnBCiwjGOTqydRtCl8CLAiEA/4W5N784C0FkcFpkYUB6vdLecJ7wsFFfNeO95AFiDew=