-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash.js
More file actions
56 lines (46 loc) · 1.19 KB
/
bash.js
File metadata and controls
56 lines (46 loc) · 1.19 KB
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
process.stdout.write("prompt > ");
const ls = require("./ls.js");
const pwd = require("./pwd.js");
const cat = require("./cat.js");
const curl = require("./curl.js");
const date = require("./date.js");
const echo = require("./echo.js");
const head = require("./head.js");
const tail = require("./tail.js");
process.stdin.on("data", (data) => {
const cmd = data.toString().trim();
if (cmd === "pwd") {
pwd(done);
}
if (cmd === "ls") {
ls(done);
}
if (cmd.split(" ")[0] === "cat") {
cat(cmd.split(" ")[1], done);
}
if (cmd.split(" ")[0] === "curl") {
curl(cmd.split(" ")[1], done);
}
if (cmd === "date") {
date(done);
}
if (cmd.split(" ")[0] === "echo") {
echo(cmd.split(" ").slice(1).join(" "), done);
}
if (cmd.split(" ")[0] === "head") {
head(cmd.split(" ")[1], done);
}
if (cmd.split(" ")[0] === "tail") {
tail(cmd.split(" ")[1], done);
}
// can use split(" ")[1] to also get the file name
//print path here
// process.stdout.write("You typed: " + cmd);
// process.stdout.write("\nprompt > ");
});
const done = (output) => {
//show output
//show prompt
process.stdout.write(output);
process.stdout.write("\nprompt > ");
};