Repository navigation
Expand file tree
/
Copy pathcommand.js
More file actions
57 lines (55 loc) · 1.48 KB
/
Copy pathcommand.js
File metadata and controls
57 lines (55 loc) · 1.48 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
/*eslint-disable */
var fs = require('fs');
module.exports = {
pwd: function() {
return process.cwd();
},
date: function() {
var date = new Date();
return date.toUTCString();
},
ls: function() {
fs.readdir('.', function(err, files) {
if (err) throw err;
files.forEach(function(file) {
console.log(file.toString());
})
});
return ""
},
echo: function(str) {
return str;
},
cat: function(filename) {
fs.readFile(filename, "UTF8", function(err, data) {
if (err) {
throw err
};
var fileContent = data;
console.log(fileContent);
});
return ""
},
head: function(filename) {
fs.readFile(filename, "UTF8", function(err, data) {
if (err) {
throw err
};
var fileContent = data;
fileContent.split('\n');
console.log(fileContent.split('\n').slice(0,5).join("\n"));
});
return ""
},
tail: function(filename) {
fs.readFile(filename, "UTF8", function(err, data) {
if (err) {
throw err
};
var fileContent = data;
var difference = fileContent.split('\n').length - 5;
console.log(fileContent.split('\n').slice(difference ,fileContent.length).join("\n"));
});
return ""
}
}