We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2ffeaf6 commit 05a11a3Copy full SHA for 05a11a3
examples/shell.js
@@ -0,0 +1,30 @@
1
+var path = require('path');
2
+var fs = require('fs');
3
+var stdin = process.openStdin();
4
+
5
+var commands = {
6
+ 'ls': function (args) {
7
+ fs.readdir(args[0] || process.cwd(), function (err, entries) {
8
+ entries.forEach(function (e) {
9
+ console.log(e);
10
+ });
11
12
+ },
13
+ 'pwd': function () {
14
+ console.log(process.cwd());
15
16
+ 'cd': function (args) {
17
+ process.chdir(path.resolve(process.cwd(), args[0]));
18
19
+ 'tail': function (args) {
20
21
+ }
22
+};
23
24
+stdin.on('data', function (d) {
25
+ var matches = d.toString().match(/(\w+)(.*)/i);
26
+ var command = matches[1].toLowerCase();
27
+ var args = matches[2].trim().split(/\s/);
28
29
+ commands[command](args);
30
+});
0 commit comments