From 4e29b98ddfec7bfd8cab1dcd3f25de8d25728872 Mon Sep 17 00:00:00 2001 From: dominicbraam Date: Mon, 20 Jun 2022 18:41:04 -0400 Subject: [PATCH] added feature to exclude commands based on user config --- README.md | 5 +++++ config.json | 2 ++ src/components/input.tsx | 3 ++- src/utils/bin/commands.ts | 13 +++++++++---- src/utils/commandExclude.ts | 7 +++++++ src/utils/shell.ts | 3 ++- 6 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 src/utils/commandExclude.ts diff --git a/README.md b/README.md index 8223684..08f6446 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,11 @@ Learn more about Docker [here](https://docs.docker.com/get-started/overview/ 'he "github": // your handle "linkedin": // your handle }, + "excluded_commands": [ + // list of commands you would like to exclude + "command_1", + "command_n" + ], "email": // your email "ps1_hostname": "liveterm" // hostname in prompt "ps1_username": "visitor", // username in prompt diff --git a/config.json b/config.json index d1fa47c..a598412 100644 --- a/config.json +++ b/config.json @@ -16,6 +16,8 @@ "paypal": "https://paypal.me/cveinnt", "patreon": "https://patreon.com/cveinnt" }, + "excluded_commands": [ + ], "colors": { "light": { "background": "#FBF1C9", diff --git a/src/components/input.tsx b/src/components/input.tsx index bf9de68..f5613a8 100644 --- a/src/components/input.tsx +++ b/src/components/input.tsx @@ -3,6 +3,7 @@ import { commandExists } from '../utils/commandExists'; import { shell } from '../utils/shell'; import { handleTabCompletion } from '../utils/tabCompletion'; import { Ps1 } from './Ps1'; +import { commandExclude } from '../utils/commandExclude'; export const Input = ({ inputRef, @@ -89,7 +90,7 @@ export const Input = ({ id="prompt" type="text" className={`bg-light-background dark:bg-dark-background focus:outline-none flex-grow ${ - commandExists(command) || command === '' + (commandExists(command) || command === '') && !commandExclude(command) ? 'text-dark-green' : 'text-dark-red' }`} diff --git a/src/utils/bin/commands.ts b/src/utils/bin/commands.ts index 338c9f8..da6e8b9 100644 --- a/src/utils/bin/commands.ts +++ b/src/utils/bin/commands.ts @@ -2,16 +2,21 @@ import * as bin from './index'; import config from '../../../config.json'; +import { commandExclude } from '../commandExclude'; // Help export const help = async (args: string[]): Promise => { const commands = Object.keys(bin).sort().join(', '); var c = ''; + var included_count = 1; for (let i = 1; i <= Object.keys(bin).sort().length; i++) { - if (i % 7 === 0) { - c += Object.keys(bin).sort()[i - 1] + '\n'; - } else { - c += Object.keys(bin).sort()[i - 1] + ' '; + if (!(commandExclude(Object.keys(bin).sort()[i-1]))){ + if (included_count % 7 === 0) { + c += Object.keys(bin).sort()[i - 1] + '\n'; + } else { + c += Object.keys(bin).sort()[i - 1] + ' '; + } + included_count++; } } return `Welcome! Here are all the available commands: diff --git a/src/utils/commandExclude.ts b/src/utils/commandExclude.ts new file mode 100644 index 0000000..0133333 --- /dev/null +++ b/src/utils/commandExclude.ts @@ -0,0 +1,7 @@ +import config from '../../config.json'; + +var exception_commands = [ 'banner' , 'help' ] + +export const commandExclude = (command: string) => { + return config.excluded_commands.includes(command) && !(exception_commands.includes(command)) +} diff --git a/src/utils/shell.ts b/src/utils/shell.ts index 587a733..50dc887 100644 --- a/src/utils/shell.ts +++ b/src/utils/shell.ts @@ -1,5 +1,6 @@ import React from 'react'; import * as bin from './bin'; +import { commandExclude } from '../utils/commandExclude'; export const shell = async ( command: string, @@ -14,7 +15,7 @@ export const shell = async ( clearHistory(); } else if (command === '') { setHistory(''); - } else if (Object.keys(bin).indexOf(args[0]) === -1) { + } else if (Object.keys(bin).indexOf(args[0]) === -1 || commandExclude(args[0])) { setHistory( `shell: command not found: ${args[0]}. Try 'help' to get started.`, );