-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.js
More file actions
69 lines (60 loc) · 1.36 KB
/
Copy pathcommands.js
File metadata and controls
69 lines (60 loc) · 1.36 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
57
58
59
60
61
62
63
64
65
66
67
68
69
var fs = require('fs');
var request = require('request');
module.exports = {
pwd: function(file, done){
var output = process.cwd();
done(output);
// process.stdout.write(process.cwd());
// process.stdout.write('\nprompt > ');
},
date: function(file, done){
var date = new Date();
var dateString = date.toString();
done(dateString);
},
ls: function(file, done){
var output = "";
fs.readdir('.', function(err, files) {
if (err) throw err;
files.forEach(function(file) {
output += (file.toString() + '\n');
})
done(output);
});
},
echo: function(file, done){
done(file);
},
cat: function(file, done){
fs.readFile(file, function(err, data){
if (err) throw err;
done(data);
})
},
head: function(file, done){
fs.readFile(file, function(err, data){
if (err) throw err;
var contentString =
data.toString().split("\n").slice(0,5).join('\n');
done(contentString);
})
},
tail: function(file, done){
fs.readFile(file, function(err, data){
if (err) throw err;
var contentString =
data.toString().split("\n").slice(-5).join('\n');
done(contentString);
})
},
curl: function(file, done){
var output = "";
request(file, function(error, response, body){
if(error) throw error;
if(!error && response.statusCode == 200){
output += body;
done(output);
}
})
}
};