add tree.ts
This commit is contained in:
@@ -209,6 +209,15 @@
|
|||||||
"publish_time": 1768111677531,
|
"publish_time": 1768111677531,
|
||||||
"update_time": 1769359601445
|
"update_time": 1769359601445
|
||||||
},
|
},
|
||||||
|
"tree.ts": {
|
||||||
|
"script_name": "tree.ts",
|
||||||
|
"script_length": 2191,
|
||||||
|
"script_sha256": "de953afc79f0e3c8419e16d9ed0efb00b04ae59688a8ee34c4013b0279b877ca",
|
||||||
|
"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": 1769361581018
|
||||||
|
},
|
||||||
"wget.ts": {
|
"wget.ts": {
|
||||||
"script_name": "wget.ts",
|
"script_name": "wget.ts",
|
||||||
"script_length": 4076,
|
"script_length": 4076,
|
||||||
|
|||||||
64
single-scripts/tree.ts
Executable file
64
single-scripts/tree.ts
Executable file
@@ -0,0 +1,64 @@
|
|||||||
|
#!/usr/bin/env runts -- --allow-read --allow-import
|
||||||
|
|
||||||
|
import {formatSize2, joinPath, log, term,} from "https://global.hatter.ink/script/get/@16/deno-commons-mod.ts";
|
||||||
|
|
||||||
|
const defaultSkipDirs = [".git", ".idea", ".gradle", "target"];
|
||||||
|
|
||||||
|
async function listDir(
|
||||||
|
dir: string,
|
||||||
|
depth: number,
|
||||||
|
maxDepth: number,
|
||||||
|
): Promise<void> {
|
||||||
|
const tab = " ".repeat(depth * 4);
|
||||||
|
try {
|
||||||
|
for await (const dirEntry of Deno.readDir(dir)) {
|
||||||
|
if (defaultSkipDirs.includes(dirEntry.name)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const fullName = joinPath(dir, dirEntry.name);
|
||||||
|
if (dirEntry.isDirectory) {
|
||||||
|
const showNextDepth = depth <= maxDepth;
|
||||||
|
console.log(
|
||||||
|
`${tab}- [${dirEntry.name}]${
|
||||||
|
showNextDepth ? "" : " ...more dirs..."
|
||||||
|
}`,
|
||||||
|
);
|
||||||
|
if (showNextDepth) {
|
||||||
|
await listDir(fullName, depth + 1, maxDepth);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let fileDesc = "";
|
||||||
|
if (dirEntry.isSymlink) {
|
||||||
|
fileDesc = " 🔗";
|
||||||
|
} else if (dirEntry.isFile) {
|
||||||
|
const fileInfo = await Deno.stat(fullName);
|
||||||
|
if (fileInfo.size > 1024 * 1024) {
|
||||||
|
fileDesc = term.red(` - ${formatSize2(fileInfo.size)}`);
|
||||||
|
} else {
|
||||||
|
fileDesc = term.yellow(
|
||||||
|
` - ${formatSize2(fileInfo.size)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(
|
||||||
|
`${tab}- ${term.green(dirEntry.name)} ${fileDesc}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(term.red(`${tab} ERROR: ${e.message}`));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main(): Promise<void> {
|
||||||
|
let baseDir = ".";
|
||||||
|
if (Deno.args.length > 0) {
|
||||||
|
baseDir = Deno.args[0];
|
||||||
|
}
|
||||||
|
await listDir(baseDir, 0, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch((e) => log.error(e));
|
||||||
|
|
||||||
|
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260126T011930+08:00.MEUCIQDGcKujeENYovKiJ/LY
|
||||||
|
// 0hWJTrmhrGRr4lAb7OP0M3K43gIgVa3LNCnH8EYss9/rGgbQlZVEBiPVKqRh6BsMfUDs5Tc=
|
||||||
Reference in New Issue
Block a user