How would I parse a shell string in JS?

93 views Asked by At

So I'm creating a terminal environment using XTerm.js, and I want to parse shell commands like so:

echo hi >> cool.txt && neofetch

would become

[
  { command: 'echo', args: ['hi'], operators: [{ operator: '>>', to: 'cool.txt' }] },
  { command: 'neofetch' }
]

I would like to have all the bash operators preferably.

I've so far tried using npm libraries such as shell-quote, however they do not satisfy my needs.

0

There are 0 answers