summaryrefslogtreecommitdiff
path: root/Components/ChangeDir/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/ChangeDir/index.js
downloadmistyos-og-7923aa8942b55884320ef2428417e3ee4b121613.tar.gz
mistyos-og-7923aa8942b55884320ef2428417e3ee4b121613.tar.bz2
mistyos-og-7923aa8942b55884320ef2428417e3ee4b121613.zip
Initial commitHEADmane
Diffstat (limited to 'Components/ChangeDir/index.js')
-rw-r--r--Components/ChangeDir/index.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/Components/ChangeDir/index.js b/Components/ChangeDir/index.js
new file mode 100644
index 0000000..db9d82e
--- /dev/null
+++ b/Components/ChangeDir/index.js
@@ -0,0 +1,27 @@
+const fs = require('fs');
+const path = require('path');
+const chalk = require(__dirname + '/../../MistyCore/node_modules/chalk');
+
+module.exports = (arguments) => {
+ if (arguments._finals.length > 0) {
+ let newDirectory = path.resolve(arguments._finals[0]);
+
+ if (fs.existsSync(newDirectory)) {
+ try {
+ fs.accessSync(newDirectory, fs.constants.R_OK);
+
+ if (!fs.lstatSync(newDirectory).isDirectory()) {
+ console.log(chalk.bgYellow.white("<!>") + " " + chalk.yellow("Not a directory: ") + arguments['_finals'][0]);
+ } else {
+ process.chdir(newDirectory);
+ }
+ } catch (e) {
+ console.log(chalk.bgYellow.white("<!>") + " " + chalk.yellow("Permission denied: ") + arguments['_finals'][0]);
+ }
+ } else {
+ console.log(chalk.bgYellow.white("<!>") + " " + chalk.yellow("No such file or directory: ") + arguments['_finals'][0]);
+ }
+ } else {
+ console.log(chalk.bgYellow.white("<!>") + " " + chalk.yellow("Missing operand"));
+ }
+} \ No newline at end of file