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 1527ac2 commit 9983327Copy full SHA for 9983327
implement-shell-tools/ls/ls.js
@@ -17,8 +17,15 @@ const directory = program.args[0] || "."; //get dir arg- 1st arg in program.args
17
18
let files = await fs.readdir(directory); //read the dir to get array of filenames
19
20
-
21
-if (!options.all) { //Handle -a (include hidden files)
+//Handle -a (include hidden files)
+// Node's fs.readdir() does not include the special directory entries "." (current dir)
22
+// and ".." (parent dir). The real `ls -a` command shows them, so we add them manually here
23
+// to match the behavior of `ls -a`.
24
+if (options.all) {
25
+
26
+ files.unshift("..");
27
+ files.unshift(".");
28
+} else {
29
files = files.filter(name => !name.startsWith("."));
30
}
31
0 commit comments