jquery.terminal icon indicating copy to clipboard operation
jquery.terminal copied to clipboard

Multi-word commands

Open SynergyBest opened this issue 4 years ago • 4 comments

I have question related to jQuery Terminal

How do you make commands multiple words? I'm trying to make a joke "sudo rm -rf" command but when I try it, it only says "command sudo not fount"

SynergyBest avatar Dec 22 '20 19:12 SynergyBest

there are two ways:

$('...').terminal(function(command) {
   // command will be "sudo rm -rf"
   // but it will not work if something type double space between sudo and rm or rm and -rf
});

or you can use this:

$('...').terminal({
  sudo: function(command, ...args) {
       // command will be rm and args will be ["-rf"]
  }
});

with second usage you can handle different commands like:

if (command == 'rm') {
} else if (command == 'mv') {
} else if (command ==='cp') {
}

or use any logic you want.

With first you will need to parse the command yourself. but there are also helpers for that like $.terminal.parse_command or $.terminal.split_command (split will not change "10" into 10). All functions are in api reference page. But I need to work a bit on documentation, maybe some tutorials.

jcubic avatar Dec 22 '20 21:12 jcubic

Also to make ...args working you will need checkArity: false because by default the library is checking how many arguments you have.

jcubic avatar Dec 22 '20 21:12 jcubic

@SynergyBest please do not close this issue, I use it to remember to add this to documentation.

jcubic avatar Apr 18 '22 13:04 jcubic

Oh, sorry!

SynergyBest avatar Apr 18 '22 18:04 SynergyBest