added feature to exclude commands based on user config

pull/27/head
dominicbraam 2 years ago
parent 1f2e543bdb
commit 4e29b98ddf

@ -82,6 +82,11 @@ Learn more about Docker [here](https://docs.docker.com/get-started/overview/ 'he
"github": // your handle "github": // your handle
"linkedin": // your handle "linkedin": // your handle
}, },
"excluded_commands": [
// list of commands you would like to exclude
"command_1",
"command_n"
],
"email": // your email "email": // your email
"ps1_hostname": "liveterm" // hostname in prompt "ps1_hostname": "liveterm" // hostname in prompt
"ps1_username": "visitor", // username in prompt "ps1_username": "visitor", // username in prompt

@ -16,6 +16,8 @@
"paypal": "https://paypal.me/cveinnt", "paypal": "https://paypal.me/cveinnt",
"patreon": "https://patreon.com/cveinnt" "patreon": "https://patreon.com/cveinnt"
}, },
"excluded_commands": [
],
"colors": { "colors": {
"light": { "light": {
"background": "#FBF1C9", "background": "#FBF1C9",

@ -3,6 +3,7 @@ import { commandExists } from '../utils/commandExists';
import { shell } from '../utils/shell'; import { shell } from '../utils/shell';
import { handleTabCompletion } from '../utils/tabCompletion'; import { handleTabCompletion } from '../utils/tabCompletion';
import { Ps1 } from './Ps1'; import { Ps1 } from './Ps1';
import { commandExclude } from '../utils/commandExclude';
export const Input = ({ export const Input = ({
inputRef, inputRef,
@ -89,7 +90,7 @@ export const Input = ({
id="prompt" id="prompt"
type="text" type="text"
className={`bg-light-background dark:bg-dark-background focus:outline-none flex-grow ${ 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-green'
: 'text-dark-red' : 'text-dark-red'
}`} }`}

@ -2,16 +2,21 @@
import * as bin from './index'; import * as bin from './index';
import config from '../../../config.json'; import config from '../../../config.json';
import { commandExclude } from '../commandExclude';
// Help // Help
export const help = async (args: string[]): Promise<string> => { export const help = async (args: string[]): Promise<string> => {
const commands = Object.keys(bin).sort().join(', '); const commands = Object.keys(bin).sort().join(', ');
var c = ''; var c = '';
var included_count = 1;
for (let i = 1; i <= Object.keys(bin).sort().length; i++) { for (let i = 1; i <= Object.keys(bin).sort().length; i++) {
if (i % 7 === 0) { if (!(commandExclude(Object.keys(bin).sort()[i-1]))){
c += Object.keys(bin).sort()[i - 1] + '\n'; if (included_count % 7 === 0) {
} else { c += Object.keys(bin).sort()[i - 1] + '\n';
c += Object.keys(bin).sort()[i - 1] + ' '; } else {
c += Object.keys(bin).sort()[i - 1] + ' ';
}
included_count++;
} }
} }
return `Welcome! Here are all the available commands: return `Welcome! Here are all the available commands:

@ -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))
}

@ -1,5 +1,6 @@
import React from 'react'; import React from 'react';
import * as bin from './bin'; import * as bin from './bin';
import { commandExclude } from '../utils/commandExclude';
export const shell = async ( export const shell = async (
command: string, command: string,
@ -14,7 +15,7 @@ export const shell = async (
clearHistory(); clearHistory();
} else if (command === '') { } else if (command === '') {
setHistory(''); setHistory('');
} else if (Object.keys(bin).indexOf(args[0]) === -1) { } else if (Object.keys(bin).indexOf(args[0]) === -1 || commandExclude(args[0])) {
setHistory( setHistory(
`shell: command not found: ${args[0]}. Try 'help' to get started.`, `shell: command not found: ${args[0]}. Try 'help' to get started.`,
); );

Loading…
Cancel
Save