-
Notifications
You must be signed in to change notification settings - Fork 1
/
commands.js
61 lines (55 loc) · 1.4 KB
/
commands.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* commands.js
*
* Author: Diego Rivera
*
* Shell terminal commands
*/
async function ls(args) {
var originalPath;
if (args[0] && args[0].trim().indexOf("-") != 0) {
originalPath = [...currentPath];
try {
await changeDir(args[0]);
} catch (error) {
showDisplay(error);
showPrompt();
return;
}
}
var contents = await getCurentPathContents();
var list = "total " + Object.keys(contents.childs).length + "<br/>";
list += lsLine(".", contents);
list += lsLine("..", contents);
for (const child in contents.childs) {
try {
list += lsLine(child, contents.childs[child]);
} catch (e) {
console.log(e)
}
}
if (!!originalPath) {
currentPath = originalPath;
}
showDisplay(list);
showPrompt();
}
async function cd(args) {
if (args.length == 0 || args[0].trim() == "~") {
currentPath = [];
} else {
try {
await changeDir(args[0]);
} catch (error) {
showDisplay(error);
}
}
showPrompt();
}
function help() {
let help = "<b>ls</b> [dir] -- list [dir] (current directory if not specified) contents<br/>"
+ "<b>cd</b> [dir] -- change directory to [dir] (home if not specified)<br/>";
showDisplay(help);
showPrompt();
}