We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b40010c commit 19cae55Copy full SHA for 19cae55
1 file changed
implement-shell-tools/ls/ls.js
@@ -0,0 +1,30 @@
1
+import { promises as fs } from "node:fs";
2
+import process from "node:process";
3
+
4
+const args = process.argv.slice(2);
5
6
+const showHidden = args.includes("-a");
7
8
+const paths = args.filter((arg) => !arg.startsWith("-"));
9
10
+const targetPath = paths.length > 0 ? paths[0] : process.cwd();
11
12
+let entries = await fs.readdir(targetPath);
13
14
+if (!showHidden) {
15
+ entries = entries.filter((entry) => !entry.startsWith("."));
16
+}
17
18
+if (showHidden) {
19
+ entries = [".", "..", ...entries];
20
21
22
+entries.sort((a, b) => {
23
+ const cleanA = a.replace(/^\.+/, "");
24
+ const cleanB = b.replace(/^\.+/, "");
25
+ return cleanA.localeCompare(cleanB);
26
+});
27
28
+for (const entry of entries) {
29
+ process.stdout.write(entry + "\n");
30
0 commit comments