@bashlife/boxbox-beta 69.0.0

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.
Files changed (76) hide show
  1. package/bin/boxbox.js +3 -0
  2. package/package.json +20 -0
  3. package/src/commands/JavaScriptRun/Loader.js +47 -0
  4. package/src/commands/JavaScriptRun/ModuleLoader.js +11 -0
  5. package/src/commands/JavaScriptRun/index.js +61 -0
  6. package/src/commands/JavaScriptRun/init.js +34 -0
  7. package/src/commands/JavaScriptRun/jsRun.js +111 -0
  8. package/src/commands/awk.js +58 -0
  9. package/src/commands/basename.js +10 -0
  10. package/src/commands/cal.js +33 -0
  11. package/src/commands/call.js +115 -0
  12. package/src/commands/cat.js +16 -0
  13. package/src/commands/cd.sh +12 -0
  14. package/src/commands/chmod.js +27 -0
  15. package/src/commands/clear.js +3 -0
  16. package/src/commands/cp.js +17 -0
  17. package/src/commands/curl.js +80 -0
  18. package/src/commands/cut.js +42 -0
  19. package/src/commands/date.js +5 -0
  20. package/src/commands/df.js +35 -0
  21. package/src/commands/diff.js +33 -0
  22. package/src/commands/dirname.js +10 -0
  23. package/src/commands/du.js +31 -0
  24. package/src/commands/echo.js +32 -0
  25. package/src/commands/env.js +38 -0
  26. package/src/commands/expr.js +97 -0
  27. package/src/commands/file.js +35 -0
  28. package/src/commands/find.js +25 -0
  29. package/src/commands/fmt.js +36 -0
  30. package/src/commands/fold.js +40 -0
  31. package/src/commands/grep.js +25 -0
  32. package/src/commands/groups.js +6 -0
  33. package/src/commands/head.js +23 -0
  34. package/src/commands/help.js +41 -0
  35. package/src/commands/hexdump.js +40 -0
  36. package/src/commands/hostname.js +5 -0
  37. package/src/commands/id.js +6 -0
  38. package/src/commands/info.js +47 -0
  39. package/src/commands/join.js +40 -0
  40. package/src/commands/kill.js +17 -0
  41. package/src/commands/ln.js +33 -0
  42. package/src/commands/ls.js +8 -0
  43. package/src/commands/mkdir.js +17 -0
  44. package/src/commands/mv.js +18 -0
  45. package/src/commands/od.js +32 -0
  46. package/src/commands/paste.js +28 -0
  47. package/src/commands/preview.js +38 -0
  48. package/src/commands/printenv.js +15 -0
  49. package/src/commands/printf.js +47 -0
  50. package/src/commands/ps.js +16 -0
  51. package/src/commands/pwd.js +3 -0
  52. package/src/commands/readlink.js +17 -0
  53. package/src/commands/rm.js +60 -0
  54. package/src/commands/rmdir.js +28 -0
  55. package/src/commands/sed.js +103 -0
  56. package/src/commands/seq.js +17 -0
  57. package/src/commands/sleep.js +17 -0
  58. package/src/commands/sort.js +24 -0
  59. package/src/commands/split.js +30 -0
  60. package/src/commands/strings.js +26 -0
  61. package/src/commands/tail.js +23 -0
  62. package/src/commands/tee.js +22 -0
  63. package/src/commands/touch.js +12 -0
  64. package/src/commands/tr.js +33 -0
  65. package/src/commands/tree.js +47 -0
  66. package/src/commands/tty.js +7 -0
  67. package/src/commands/uname.js +33 -0
  68. package/src/commands/uniq.js +29 -0
  69. package/src/commands/uptime.js +18 -0
  70. package/src/commands/version.js +20 -0
  71. package/src/commands/wc.js +22 -0
  72. package/src/commands/which.js +24 -0
  73. package/src/commands/whoami.js +5 -0
  74. package/src/commands/xargs.js +34 -0
  75. package/src/commands/yes.js +7 -0
  76. package/src/index.js +194 -0
@@ -0,0 +1,22 @@
1
+ import fs from "fs";
2
+
3
+ export default function tee(args) {
4
+ if (!args[0]) {
5
+ console.log("Usage: tee file");
6
+ return;
7
+ }
8
+
9
+ const file = args[0];
10
+
11
+ let input = "";
12
+
13
+ process.stdin.on("data", chunk => {
14
+ input += chunk.toString();
15
+ });
16
+
17
+ process.stdin.on("end", () => {
18
+ fs.writeFileSync(file, input);
19
+
20
+ process.stdout.write(input);
21
+ });
22
+ }
@@ -0,0 +1,12 @@
1
+ import fs from "fs";
2
+
3
+ export default function(args) {
4
+ const file = args[0];
5
+
6
+ if (!file) {
7
+ console.log("Usage: touch <file>");
8
+ return;
9
+ }
10
+
11
+ fs.closeSync(fs.openSync(file, "a"));
12
+ }
@@ -0,0 +1,33 @@
1
+ import fs from "fs";
2
+
3
+ export default function tr(args) {
4
+ if (args.length < 3) {
5
+ console.log("Usage: tr SET1 SET2 file");
6
+ return;
7
+ }
8
+
9
+ const set1 = args[0];
10
+ const set2 = args[1];
11
+ const file = args[2];
12
+
13
+ if (!fs.existsSync(file)) {
14
+ console.log(`tr: ${file}: No such file`);
15
+ return;
16
+ }
17
+
18
+ const input = fs.readFileSync(file, "utf8");
19
+
20
+ let output = "";
21
+
22
+ for (const char of input) {
23
+ const index = set1.indexOf(char);
24
+
25
+ if (index !== -1 && set2[index] !== undefined) {
26
+ output += set2[index];
27
+ } else {
28
+ output += char;
29
+ }
30
+ }
31
+
32
+ console.log(output);
33
+ }
@@ -0,0 +1,47 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ export default function(args) {
5
+ const start = args[0] && !args[0].startsWith("--")
6
+ ? args[0]
7
+ : ".";
8
+
9
+ const ignoreIndex = args.indexOf("--ignore");
10
+ const ignored = ignoreIndex !== -1 ? args[ignoreIndex + 1] : null;
11
+
12
+ function printTree(dir, prefix = "") {
13
+ let entries;
14
+
15
+ try {
16
+ entries = fs.readdirSync(dir);
17
+ } catch (err) {
18
+ console.log(`tree: ${err.message}`);
19
+ return;
20
+ }
21
+
22
+ if (ignored) {
23
+ entries = entries.filter(entry => entry !== ignored);
24
+ }
25
+
26
+ entries.forEach((entry, index) => {
27
+ const fullPath = path.join(dir, entry);
28
+ const last = index === entries.length - 1;
29
+
30
+ console.log(
31
+ prefix + (last ? "└── " : "├── ") + entry
32
+ );
33
+
34
+ try {
35
+ if (fs.statSync(fullPath).isDirectory()) {
36
+ printTree(
37
+ fullPath,
38
+ prefix + (last ? " " : "│ ")
39
+ );
40
+ }
41
+ } catch {}
42
+ });
43
+ }
44
+
45
+ console.log(start);
46
+ printTree(start);
47
+ }
@@ -0,0 +1,7 @@
1
+ export default function tty() {
2
+ if (process.stdin.isTTY) {
3
+ console.log(process.stdin.isTTY ? "/dev/tty" : "not a tty");
4
+ } else {
5
+ console.log("not a tty");
6
+ }
7
+ }
@@ -0,0 +1,33 @@
1
+ import os from "os";
2
+
3
+ export default function(args) {
4
+ const option = args[0];
5
+
6
+ if (!option) {
7
+ console.log(os.type());
8
+ return;
9
+ }
10
+
11
+ switch (option) {
12
+ case "-a":
13
+ console.log(
14
+ `${os.type()} ${os.hostname()} ${os.release()} ${os.arch()}`
15
+ );
16
+ break;
17
+
18
+ case "-s":
19
+ console.log(os.type());
20
+ break;
21
+
22
+ case "-r":
23
+ console.log(os.release());
24
+ break;
25
+
26
+ case "-m":
27
+ console.log(os.arch());
28
+ break;
29
+
30
+ default:
31
+ console.log("Usage: uname [-a|-s|-r|-m]");
32
+ }
33
+ }
@@ -0,0 +1,29 @@
1
+ import fs from "fs";
2
+
3
+ export default function(args) {
4
+ const file = args[0];
5
+
6
+ if (!file) {
7
+ console.log("Usage: uniq <file>");
8
+ return;
9
+ }
10
+
11
+ try {
12
+ const content = fs.readFileSync(file, "utf8");
13
+
14
+ const lines = content.split("\n");
15
+
16
+ const unique = [];
17
+
18
+ for (const line of lines) {
19
+ if (unique[unique.length - 1] !== line) {
20
+ unique.push(line);
21
+ }
22
+ }
23
+
24
+ console.log(unique.join("\n"));
25
+
26
+ } catch (err) {
27
+ console.log(`uniq: ${err.message}`);
28
+ }
29
+ }
@@ -0,0 +1,18 @@
1
+ export default function uptime() {
2
+ const seconds = Math.floor(process.uptime());
3
+
4
+ const days = Math.floor(seconds / 86400);
5
+ const hours = Math.floor((seconds % 86400) / 3600);
6
+ const minutes = Math.floor((seconds % 3600) / 60);
7
+ const secs = seconds % 60;
8
+
9
+ let output = "";
10
+
11
+ if (days > 0) output += `${days} day${days !== 1 ? "s" : ""}, `;
12
+ if (hours > 0) output += `${hours} hour${hours !== 1 ? "s" : ""}, `;
13
+ if (minutes > 0) output += `${minutes} minute${minutes !== 1 ? "s" : ""}, `;
14
+
15
+ output += `${secs} second${secs !== 1 ? "s" : ""}`;
16
+
17
+ console.log(`up ${output}`);
18
+ }
@@ -0,0 +1,20 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ export default function version() {
5
+ const packagePath = path.join(
6
+ process.cwd(),
7
+ "package.json"
8
+ );
9
+
10
+ if (!fs.existsSync(packagePath)) {
11
+ console.log("BoxBox version unknown");
12
+ return;
13
+ }
14
+
15
+ const pkg = JSON.parse(
16
+ fs.readFileSync(packagePath, "utf8")
17
+ );
18
+
19
+ console.log(`BoxBox ${pkg.version}`);
20
+ }
@@ -0,0 +1,22 @@
1
+ import fs from "fs";
2
+
3
+ export default function(args) {
4
+ const file = args[0];
5
+
6
+ if (!file) {
7
+ console.log("Usage: wc <file>");
8
+ return;
9
+ }
10
+
11
+ try {
12
+ const data = fs.readFileSync(file, "utf8");
13
+
14
+ const lines = data.split("\n").length;
15
+ const words = data.trim().split(/\s+/).filter(Boolean).length;
16
+ const bytes = Buffer.byteLength(data);
17
+
18
+ console.log(`${lines} ${words} ${bytes} ${file}`);
19
+ } catch (err) {
20
+ console.log(`wc: ${err.message}`);
21
+ }
22
+ }
@@ -0,0 +1,24 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ export default function(args) {
5
+ const command = args[0];
6
+
7
+ if (!command) {
8
+ console.log("Usage: which <command>");
9
+ return;
10
+ }
11
+
12
+ const paths = process.env.PATH.split(":");
13
+
14
+ for (const dir of paths) {
15
+ const file = path.join(dir, command);
16
+
17
+ if (fs.existsSync(file)) {
18
+ console.log(file);
19
+ return;
20
+ }
21
+ }
22
+
23
+ console.log(`${command}: not found`);
24
+ }
@@ -0,0 +1,5 @@
1
+ import os from "os";
2
+
3
+ export default function whoami() {
4
+ console.log(os.userInfo().username);
5
+ }
@@ -0,0 +1,34 @@
1
+ import { spawnSync } from "child_process";
2
+
3
+ export default function xargs(args) {
4
+ if (args.length === 0) {
5
+ console.log("xargs: missing command");
6
+ return;
7
+ }
8
+
9
+ const command = args[0];
10
+ const commandArgs = args.slice(1);
11
+
12
+ let input = "";
13
+
14
+ process.stdin.on("data", chunk => {
15
+ input += chunk;
16
+ });
17
+
18
+ process.stdin.on("end", () => {
19
+ const items = input
20
+ .trim()
21
+ .split(/\s+/)
22
+ .filter(Boolean);
23
+
24
+ const result = spawnSync(
25
+ command,
26
+ [...commandArgs, ...items],
27
+ { stdio: "inherit" }
28
+ );
29
+
30
+ if (result.error) {
31
+ console.log(`xargs: ${result.error.message}`);
32
+ }
33
+ });
34
+ }
@@ -0,0 +1,7 @@
1
+ export default function yes(args) {
2
+ const text = args.length > 0 ? args.join(" ") : "y";
3
+
4
+ while (true) {
5
+ console.log(text);
6
+ }
7
+ }
package/src/index.js ADDED
@@ -0,0 +1,194 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { execFile } from "child_process";
4
+
5
+ const args = process.argv.slice(2);
6
+ const command = args[0];
7
+
8
+ const commands = {
9
+ rmdir: "./commands/rmdir.js",
10
+ javascript: "./commands/JavaScriptRun/index.js",
11
+ printf: "./commands/printf.js",
12
+ readlink: "./commands/readlink.js",
13
+ xargs: "./commands/xargs.js",
14
+ expr: "./commands/expr.js",
15
+ env: "./commands/env.js",
16
+ ps: "./commands/ps.js",
17
+ uptime: "./commands/uptime.js",
18
+ hexdump: "./commands/hexdump.js",
19
+ od: "./commands/od.js",
20
+ strings: "./commands/strings.js",
21
+ split: "./commands/split.js",
22
+ fmt: "./commands/fmt.js",
23
+ fold: "./commands/fold.js",
24
+ paste: "./commands/paste.js",
25
+ join: "./commands/join.js",
26
+ cal: "./commands/cal.js",
27
+ groups: "./commands/groups.js",
28
+ hostname: "./commands/hostname.js",
29
+ id: "./commands/id.js",
30
+ tty: "./commands/tty.js",
31
+ ln: "./commands/ln.js",
32
+ yes: "./commands/yes.js",
33
+ tee: "./commands/tee.js",
34
+ tr: "./commands/tr.js",
35
+ clear: "./commands/clear.js",
36
+ awk: "./commands/awk.js",
37
+ sed: "./commands/sed.js",
38
+ preview: "./commands/preview.js",
39
+ cut: "./commands/cut.js",
40
+ diff: "./commands/diff.js",
41
+ seq: "./commands/seq.js",
42
+ sleep: "./commands/sleep.js",
43
+ whoami: "./commands/whoami.js",
44
+ basename: "./commands/basename.js",
45
+ dirname: "./commands/dirname.js",
46
+ version : "./commands/version.js",
47
+ ls: "./commands/ls.js",
48
+ cat: "./commands/cat.js",
49
+ mkdir: "./commands/mkdir.js",
50
+ mv: "./commands/mv.js",
51
+ cd: "./src/commands/cd.sh",
52
+ touch: "./commands/touch.js",
53
+ echo: "./commands/echo.js",
54
+ cp: "./commands/cp.js",
55
+ rm: "./commands/rm.js",
56
+ pwd: "./commands/pwd.js",
57
+
58
+ find: "./commands/find.js",
59
+ tree: "./commands/tree.js",
60
+ wc: "./commands/wc.js",
61
+ grep: "./commands/grep.js",
62
+ head: "./commands/head.js",
63
+ tail: "./commands/tail.js",
64
+ sort: "./commands/sort.js",
65
+ uniq: "./commands/uniq.js",
66
+
67
+ which: "./commands/which.js",
68
+ uname: "./commands/uname.js",
69
+ chmod: "./commands/chmod.js",
70
+ du: "./commands/du.js",
71
+ df: "./commands/df.js",
72
+ printenv: "./commands/printenv.js",
73
+ date: "./commands/date.js",
74
+ file: "./commands/file.js",
75
+ kill: "./commands/kill.js",
76
+
77
+ call: "./commands/call.js",
78
+ curl: "./commands/curl.js",
79
+ info: "./commands/info.js",
80
+ help: "./commands/help.js"
81
+ };
82
+
83
+ if (!command || command === "help") {
84
+ console.log(`
85
+ BoxBox 65.0.2
86
+ Modern POSIX toolbox - beta
87
+
88
+ Commands:
89
+ basename Extract filename from path
90
+ ls List files
91
+ cat Show file contents
92
+ mkdir Create directory
93
+ mv Move files
94
+ cd Change directory
95
+ touch Create file
96
+ echo Print text
97
+ cp Copy files
98
+ rm Remove files
99
+ pwd Print working directory
100
+
101
+ tree Directory tree
102
+ wc Count words/lines
103
+ grep Search text
104
+ head Show first lines
105
+ tail Show last lines
106
+ sort Sort text
107
+ uniq Remove duplicates
108
+
109
+ which Find command location
110
+ uname System information
111
+ chmod Change permissions
112
+ du Disk usage
113
+ df Filesystem usage
114
+ printenv Environment variables
115
+ date Show date/time
116
+ file File information
117
+ kill Kill process
118
+
119
+ call HTTP API client
120
+ curl HTTP client
121
+ info info about boxbox
122
+ help Show help
123
+ whoami Show current user
124
+ dirname Show directory from path
125
+
126
+ find Find files
127
+ sleep pause stuff temp
128
+ seq print any number instantly
129
+ diff Compare files
130
+ clear - Clears the terminal screen
131
+ tee - Reads input and writes it to a file while also displaying it
132
+ tr - Translates or replaces characters in text
133
+ yes - Repeatedly outputs a string until stopped
134
+ ln - Creates a hard link to a file
135
+ tty - Prints the terminal device name
136
+ id - Prints user and group identity information
137
+ groups - Prints the groups a user belongs to
138
+ hostname - Prints the system hostname
139
+ cal - Displays a calendar
140
+ paste - Merges lines from files side by side
141
+ join - Joins two files using matching fields
142
+ fold - Wraps lines to a specified width
143
+ fmt - Formats text paragraphs
144
+ split - Splits a file into smaller files
145
+ strings - Extracts readable text from files
146
+ od - Displays file contents as byte values
147
+ uptime - Shows how long the system has been running
148
+ hexdump - Displays files in hexadecimal format
149
+ ps - Displays running processes
150
+ shell - Manage BoxBox shell configuration and environment settings
151
+ expr Evaluate expressions
152
+ env Run command with modified environment
153
+ awk Process text using patterns
154
+ cut Extract parts of text
155
+ sed Edit text using commands
156
+ version Show BoxBox version
157
+ preview Preview file contents
158
+ readlink Print symbolic link target
159
+ xargs Build arguments from input
160
+ printf Format and print text
161
+ javascript Run JavaScript projects with jsRun
162
+ rmdir Remove empty directories
163
+ `);
164
+
165
+ process.exit(0);
166
+ }
167
+
168
+ if (commands[command]) {
169
+ try {
170
+ const file = commands[command];
171
+
172
+ if (file.endsWith(".sh")) {
173
+ execFile("sh", [file, ...args.slice(1)], (err, stdout, stderr) => {
174
+ if (err) {
175
+ console.log(`boxbox error: ${err.message}`);
176
+ return;
177
+ }
178
+
179
+ process.stdout.write(stdout);
180
+ process.stderr.write(stderr);
181
+ });
182
+ } else {
183
+ const module = await import(file);
184
+ await module.default(args.slice(1));
185
+ }
186
+
187
+ } catch (err) {
188
+ console.log(`boxbox error: ${err.message}`);
189
+ }
190
+
191
+ } else {
192
+ console.log(`boxbox: unknown command '${command}'`);
193
+ console.log("Run 'boxbox help' for available commands.");
194
+ }