diff options
author | Minteck <contact@minteck.org> | 2022-11-28 17:31:34 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-11-28 17:31:34 +0100 |
commit | 7923aa8942b55884320ef2428417e3ee4b121613 (patch) | |
tree | 7993632f2898b1998f25b11ce40a8d2eb3d44730 /Components/ChangeDir | |
download | mistyos-og-mane.tar.gz mistyos-og-mane.tar.bz2 mistyos-og-mane.zip |
Diffstat (limited to 'Components/ChangeDir')
-rw-r--r-- | Components/ChangeDir/index.js | 27 | ||||
-rw-r--r-- | Components/ChangeDir/metadata.yml | 33 |
2 files changed, 60 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 diff --git a/Components/ChangeDir/metadata.yml b/Components/ChangeDir/metadata.yml new file mode 100644 index 0000000..3818d75 --- /dev/null +++ b/Components/ChangeDir/metadata.yml @@ -0,0 +1,33 @@ +description: Changes the directory commands work from +internal: true + +aliases: + - cd + - chdir + - chwd + +manual: + summary: | + This command changes the current working directory (CWD) for a specified directory. + + parameters: [] + + final: + name: Dir + description: The directory to change to + required: true + multiple: false + command: false + path: true + daemon: false + + examples: + - command: ChangeDir / + description: Changes directory to go to the system's root directory + + - command: ChangeDir .. + description: Changes directory to go to the parent directory + + compatibility: + mistyos: '>=1.0.0' + kernel: '>=5.10.0'
\ No newline at end of file |