bash-commandls 14.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/command +1 -0
- package/bin/command.js +53 -0
- package/index.js +14 -0
- package/lib/run.js +53 -0
- package/package +1 -0
- package/package.json +12 -0
package/bin/command
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/bin/command.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const readline = require("readline");
|
|
2
|
+
const { execSync } = require("child_process");
|
|
3
|
+
|
|
4
|
+
// ==========================
|
|
5
|
+
// EXEC FUNCTION (execSync)
|
|
6
|
+
// ==========================
|
|
7
|
+
function run(command) {
|
|
8
|
+
try {
|
|
9
|
+
const output = execSync(`bash -c "${command}"`, {
|
|
10
|
+
encoding: "utf-8",
|
|
11
|
+
stdio: "pipe",
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
console.log("\n=== CONSOLE OUTPUT ===");
|
|
15
|
+
console.log(output);
|
|
16
|
+
} catch (err) {
|
|
17
|
+
console.log("\n=== ERROR OUTPUT ===");
|
|
18
|
+
console.log(err.stdout?.toString() || err.message);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// ==========================
|
|
23
|
+
// INPUT TERMINAL LOOP
|
|
24
|
+
// ==========================
|
|
25
|
+
const rl = readline.createInterface({
|
|
26
|
+
input: process.stdin,
|
|
27
|
+
output: process.stdout,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
console.log("🟢 Online Bash Compiler Ready");
|
|
31
|
+
console.log("Type bash command below (type 'exit' to stop)\n");
|
|
32
|
+
|
|
33
|
+
function prompt() {
|
|
34
|
+
rl.question("bash> ", (input) => {
|
|
35
|
+
if (input.trim() === "exit") {
|
|
36
|
+
console.log("👋 Closing compiler...");
|
|
37
|
+
rl.close();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!input.trim()) {
|
|
42
|
+
prompt();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// RUN COMMAND
|
|
47
|
+
run(input);
|
|
48
|
+
|
|
49
|
+
prompt();
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
prompt();
|
package/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const { execSync } = require("child_process");
|
|
2
|
+
|
|
3
|
+
// exported function (module)
|
|
4
|
+
function bashCommand(cmd) {
|
|
5
|
+
try {
|
|
6
|
+
return execSync(`bash -c "${cmd}"`, {
|
|
7
|
+
encoding: "utf-8"
|
|
8
|
+
});
|
|
9
|
+
} catch (err) {
|
|
10
|
+
return err.message;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = bashCommand;
|
package/lib/run.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const readline = require("readline");
|
|
2
|
+
const { execSync } = require("child_process");
|
|
3
|
+
|
|
4
|
+
// ==========================
|
|
5
|
+
// EXEC FUNCTION (execSync)
|
|
6
|
+
// ==========================
|
|
7
|
+
function run(command) {
|
|
8
|
+
try {
|
|
9
|
+
const output = execSync(`bash -c "${command}"`, {
|
|
10
|
+
encoding: "utf-8",
|
|
11
|
+
stdio: "pipe",
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
console.log("\n=== CONSOLE OUTPUT ===");
|
|
15
|
+
console.log(output);
|
|
16
|
+
} catch (err) {
|
|
17
|
+
console.log("\n=== ERROR OUTPUT ===");
|
|
18
|
+
console.log(err.stdout?.toString() || err.message);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// ==========================
|
|
23
|
+
// INPUT TERMINAL LOOP
|
|
24
|
+
// ==========================
|
|
25
|
+
const rl = readline.createInterface({
|
|
26
|
+
input: process.stdin,
|
|
27
|
+
output: process.stdout,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
console.log("🟢 Online Bash Compiler Ready");
|
|
31
|
+
console.log("Type bash command below (type 'exit' to stop)\n");
|
|
32
|
+
|
|
33
|
+
function prompt() {
|
|
34
|
+
rl.question("bash> ", (input) => {
|
|
35
|
+
if (input.trim() === "exit") {
|
|
36
|
+
console.log("👋 Closing compiler...");
|
|
37
|
+
rl.close();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!input.trim()) {
|
|
42
|
+
prompt();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// RUN COMMAND
|
|
47
|
+
run(input);
|
|
48
|
+
|
|
49
|
+
prompt();
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
prompt();
|
package/package
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bash-commandls",
|
|
3
|
+
"version": "14.2.1",
|
|
4
|
+
"description": "A simple zero-configuration command-line bash command ls",
|
|
5
|
+
"main": "./lib/run.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "node ./bin/command.js"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"bash-command": "^14.1.1"
|
|
11
|
+
}
|
|
12
|
+
}
|