Adding custom commands to terminal along side application

365 Views Asked by At

I am working on an application where we are using xtermjs and node-pty inside of an electron application. We are adding a terminal to our application and would like to add some custom commands that are used in the terminal that are related to our application.

What are some options for adding these commands?

  • We want them installed with the application.
  • They don't have to be useable inside an 'external' terminal, but it is ok if they are. By external, i mean your normal terminal. Not our xterm & node-pty implementation.
  • And we want them to behave the same as other normal unix commands. Where you can pipe with other commands && them together and stuff.

I have played around with intercepting commands between xterm and node-pty and that was a disaster. I am now considering, just writing bash scripts for the commands and having the installer manage putting them where they need to be so they can be used.

Just wondering what my options are, thanks.

1

There are 1 best solutions below

0
On

You can simply put all your executables in a directory that you add to your PATH when you invoke the shell in your terminal emulator.

The commands will be available to the user like any others in any construct that accepts commands, regardless of the user's shell or shell version (i.e. it'll work equally well in bash, zsh and fish).

If you need the commands to coordinate with your terminal emulator (e.g. if you want to process the command in JS in your Node.js process), you can arrange that via a second environment variable containing e.g. a host/port to connect to.