-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash.js
56 lines (40 loc) · 1.07 KB
/
bash.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
// Output a prompt
// for (var keys in process){
// console.log("key: " + keys + " value: " + process[keys]);
// };
var commands = require('./commands');
process.stdout.write('1prompt > ');
// The stdin 'data' event fires after a user types in a line
process.stdin.on('data', function (data) {
var cmd = data.toString().trim();
var cmdArr = cmd.split(' ');
switch (cmdArr[0]) {
case "pwd":
commands.pwd();
process.stdout.write('\n2prompt > ');
break;
case "echo":
process.stdout.write(cmdArr.slice(1).join(' '));
process.stdout.write('\n2prompt > ');
break;
case "date":
commands.date();
process.stdout.write('\n2prompt > ');
break;
case "ls":
commands.ls(cmdArr[1]);
break;
case "cat":
commands.cat(cmdArr[1]);
break;
case "head":
commands.head(cmdArr[1]);
break;
case "tail":
commands.tail(cmdArr[1]);
break;
default:
process.stdout.write('You typed: ' + cmd);
process.stdout.write('\n2prompt > ');
}
});