From 7923aa8942b55884320ef2428417e3ee4b121613 Mon Sep 17 00:00:00 2001 From: Minteck Date: Mon, 28 Nov 2022 17:31:34 +0100 Subject: Initial commit --- Components/ChangeDir/index.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Components/ChangeDir/index.js (limited to 'Components/ChangeDir/index.js') 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 -- cgit