-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (61 loc) · 2.77 KB
/
index.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
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 Color = require('cli-color');
const child_process = require("child_process");
const rl = require("readline");
const { readdirSync, existsSync } = require('fs');
const path = require('path');
const os = require("os");
/*
███╗░░██╗███████╗██╗░░██╗
████╗░██║██╔════╝╚██╗██╔╝
██╔██╗██║█████╗░░░╚███╔╝░
██║╚████║██╔══╝░░░██╔██╗░
██║░╚███║███████╗██╔╝╚██╗
╚═╝░░╚══╝╚══════╝╚═╝░░╚═╝
This Nex Project
A Terminal Created with javascript using the runtime nodejs
*/
(async () => {
console.log(`
███╗░░██╗███████╗██╗░░██╗
████╗░██║██╔════╝╚██╗██╔╝
██╔██╗██║█████╗░░░╚███╔╝░
██║╚████║██╔══╝░░░██╔██╗░
██║░╚███║███████╗██╔╝╚██╗
╚═╝░░╚══╝╚══════╝╚═╝░░╚═╝
`);
const interface = rl.createInterface(process.stdin, process.stdout, (line) => {
let completions;
if (!line || !line.length) {
completions = readdirSync(process.cwd());
} else {
if (existsSync(line)) {
completions = readdirSync(line)
}
completions = readdirSync(process.cwd());
}
let cmds = line.split(' ');
const hits = completions.filter((c) => c.startsWith(cmds.slice(-1)));
if ((cmds.length > 1) && (hits.length === 1)) {
let lastCmd = cmds.slice(-1)[0];
let pos = lastCmd.length;
rl.line = line.slice(0, -pos).concat(hits[0]);
rl.cursor = rl.line.length + 1;
}
return [hits.length ? hits.sort() : completions.sort(), line];
});
var input = async () => {
interface.question(`${Color.greenBright(os.hostname())}:${Color.greenBright(path.basename(os.homedir()))} - ${Color.cyanBright(process.cwd())} | ${Color.yellowBright("$")}: `, (answer) => {
if (!answer || !answer.length) input();
try {
let sync = child_process.execSync(answer, { encoding: "utf-8" });
if (sync.trim()) {
console.log(sync.trim());
}
input();
} catch (err) {
input();
}
});
}
input();
})();