Repository navigation
Expand file tree
/
Copy pathstatus-bar.js
More file actions
69 lines (64 loc) · 1.78 KB
/
Copy pathstatus-bar.js
File metadata and controls
69 lines (64 loc) · 1.78 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
const path = require("path");
const os = require("os");
const chalk = require("chalk");
const { execSync } = require("child_process");
const icons = {
freebsd: chalk.red("\uf30c "),
windows: chalk.blue("\uf17a "),
linux: chalk.yellow("\uf17c "),
darwin: chalk.magenta("\uf179 "),
unknown: "\uf059"
};
const platform = icons[process.platform] || icons["unknown"];
const getGitInfo = () => {
try {
const status = execSync("git status", { stdio: "pipe" }).toString();
const changes = (status.match(/modified:/g) || []).length;
const branch = status.match(/on branch ([^\n]+)/i)[1];
return [chalk.red("\uf47f " + changes), chalk.yellow("\ue725 " + branch)];
} catch (e) {
return [];
}
};
const getNPMInfo = () => {
try {
const { name, version } = require(path.resolve(
process.cwd(),
"package.json"
));
return [
`${chalk.cyan("\ue71e " + name)}`, // package name
`${chalk.red("\uf487 " + version)}`, // package version
`${chalk.green("\ue718 " + process.version)}` // node version
];
} catch (error) {
return [];
}
};
module.exports = core => {
const bar = () => {
if (core.repl.isBusy) return;
const { username } = os.userInfo();
const time = new Date().toTimeString().slice(0, 8);
let bar = [
`${platform}${username}`, // user and os info
chalk.yellow("\ue389 ") + time, // current time
...getGitInfo(), // git info
...getNPMInfo(), // npm info
chalk.magenta(
"\uf413 " +
process
.cwd()
.split(path.sep)
.slice(-3)
.join(path.sep)
) // current path
];
core.repl.preOutput = bar.join(" ");
core.repl.clear();
core.repl.preprint();
core.repl.print();
};
bar();
setInterval(bar, 1000);
};