Skip to content

Commit

Permalink
fixed exiting, and an error on init
Browse files Browse the repository at this point in the history
  • Loading branch information
TorchedSammy committed May 31, 2020
1 parent 920f5fa commit 7d3c65d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
12 changes: 7 additions & 5 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const baseConfig = {
motd: "{bold}Welcome {cyan}%username%{reset}{bold} to {cyan}KannaShell v%ver%!\n",
askOnExit: true
}
if(!utils.config()) fs.appendFileSync(`${require("os").userInfo().homedir}\\.kannashell\\config.json`, JSON.stringify(baseConfig))
if(!utils.config()) fs.appendFileSync(`${require("os").userInfo().homedir}\\.kannaconf.json`, JSON.stringify(baseConfig, null, 4))

// Put available commands in an array.
fs.readdirSync(__dirname + "/commands/").filter(c => c.endsWith('.js')).forEach(c => {commands.push(c.slice(0, -3))})
Expand Down Expand Up @@ -82,16 +82,18 @@ utils.displayMOTD()
prompt()

ci.on('SIGINT', () => {
if(!config.askOnExit) {
if(!utils.config().askOnExit) {
ci.close()
} else {
ci.question("Are you sure that you want to exit?", (ans) => {
if(ans.match(/^y(es)?$/i)) ci.close()
console.log("")
ci.question("Are you sure that you want to exit? ", (ans) => {
if(ans.match(/^y(es)?$/i)) return ci.close()
prompt()
})
}
});

ci.on('close', () => {
console.log("\nGoodbye!")
console.log("Goodbye!")
process.exit(0)
});
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kannashell",
"version": "0.0.19",
"version": "0.0.20",
"description": "A small, light terminal shell for Windows.",
"main": "bin/index.js",
"scripts": {
Expand Down
11 changes: 6 additions & 5 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

const os = require("os")
const fs = require("fs")
const { colorMap } = require("./colorMap.json")
const Path = require("./Path.js")

Expand Down Expand Up @@ -51,11 +52,11 @@ class KannaUtils {
}

static config() {
if(require("fs").existsSync(`${os.userInfo().homedir}\\.kannashell\\config.json`)) {
return JSON.parse(require("fs").readFileSync(`${os.userInfo().homedir}\\.kannashell\\config.json`))
} else {
return false;
}
if(require("fs").existsSync(`${os.userInfo().homedir}\\.kannaconf.json`)) {
return JSON.parse(require("fs").readFileSync(`${os.userInfo().homedir}\\.kannaconf.json`))
} else {
return false;
}
}
}

Expand Down

0 comments on commit 7d3c65d

Please sign in to comment.