summaryrefslogtreecommitdiff
path: root/Components/DisplayFile/index.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-11-28 17:31:34 +0100
committerMinteck <contact@minteck.org>2022-11-28 17:31:34 +0100
commit7923aa8942b55884320ef2428417e3ee4b121613 (patch)
tree7993632f2898b1998f25b11ce40a8d2eb3d44730 /Components/DisplayFile/index.js
downloadmistyos-og-mane.tar.gz
mistyos-og-mane.tar.bz2
mistyos-og-mane.zip
Initial commitHEADmane
Diffstat (limited to 'Components/DisplayFile/index.js')
-rw-r--r--Components/DisplayFile/index.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/Components/DisplayFile/index.js b/Components/DisplayFile/index.js
new file mode 100644
index 0000000..c6b3f25
--- /dev/null
+++ b/Components/DisplayFile/index.js
@@ -0,0 +1,43 @@
+let arguments = JSON.parse(process.argv[2]);
+const chalk = require(__dirname + '/../../MistyCore/node_modules/chalk');
+const fs = require("fs");
+const child_process = require("child_process");
+
+if (arguments._finals.length > 0) {
+ for (let file of arguments._finals) {
+ if (fs.existsSync(file)) {
+ try {
+ fs.accessSync(file, fs.constants.R_OK);
+
+ if (arguments['hex']) {
+ fs.writeFileSync("/System/Volumes/VM/HexDump", require('./hex')(fs.readFileSync(file), !arguments['pagination']));
+ file = "/System/Volumes/VM/HexDump";
+ }
+
+ if (fs.lstatSync(file).isDirectory()) {
+ console.log(chalk.bgYellow.white("<!>") + " " + chalk.yellow("Is a directory: ") + file);
+ } else {
+ if (arguments['pagination']) {
+ console.clear();
+ child_process.execFileSync("/System/Binaries/busybox", [ "less", "-~", "-S", "--", file ], { stdio: "inherit" });
+ console.clear();
+ } else {
+ if (arguments['search']) {
+ console.log(chalk.white(fs.readFileSync(file).toString().replace(arguments['search'], chalk.bold.red(arguments['search']))));
+ } else {
+ console.log(chalk.white(fs.readFileSync(file).toString()));
+ }
+ }
+ }
+
+ if (fs.existsSync("/System/Volumes/VM/HexDump")) fs.unlinkSync("/System/Volumes/VM/HexDump");
+ } catch (e) {
+ console.log(chalk.bgYellow.white("<!>") + " " + chalk.yellow("Permission denied: ") + file);
+ }
+ } else {
+ console.log(chalk.bgYellow.white("<!>") + " " + chalk.yellow("No such file or directory: ") + file);
+ }
+ }
+} else {
+ console.log(chalk.bgYellow.white("<!>") + " " + chalk.yellow("Missing operand"));
+} \ No newline at end of file