forked from julia-catalano/node-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash.js
33 lines (32 loc) · 914 Bytes
/
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
//output a prompt
process.stdout.write('prompt > ');
const done = (output) => {
console.log(output);
process.stdout.write('prompt > ');
}
//The stdin 'data' event fires after a user types in a line
process.stdin.on('data', (data) => {
const cmd = data.toString().trim(); //removes the newline
let cmd1 = '';
let cmdArg = '';
if (cmd.includes(' ')){
const cmdArr = cmd.split(' ');
cmd1 = cmdArr[0];
cmdArg = cmdArr[1];
}
if (cmd === 'pwd'){
const pwd = require('./pwd');
pwd(done);
} else if (cmd === 'ls') {
const ls = require('./ls');
ls(done);
} else if (cmd1 === 'cat'){
const cat = require('./cat');
cat(done, cmdArg);
} else if (cmd1 === 'curl'){
const curl = require('./curl');
curl(done, cmdArg);
} else {
process.stdout.write('You typed: ' + cmd);
}
})