简体   繁体   English

将自定义命令添加到侧边应用程序的终端

[英]Adding custom commands to terminal along side application

I am working on an application where we are using xtermjs and node-pty inside of an electron application.我正在开发一个应用程序,我们在电子应用程序中使用xtermjsnode-pty 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.不是我们的 xterm 和 node-pty 实现。
  • And we want them to behave the same as other normal unix commands.我们希望它们的行为与其他普通的 unix 命令相同。 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.我在 xterm 和 node-pty 之间尝试过拦截命令,这是一场灾难。 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.我现在正在考虑,只需为命令编写 bash 脚本并让安装程序管理将它们放置在需要的位置以便可以使用它们。

Just wondering what my options are, thanks.只是想知道我的选择是什么,谢谢。

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.当您在终端模拟器中调用 shell 时,您可以简单地将所有可执行文件放在添加到PATH的目录中。

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 (ie it'll work equally well in bash , zsh and fish ).无论用户的 shell 或 shell 版本如何(即它在bashzshfish都可以很好地工作),用户可以像在任何接受命令的构造中的任何其他人一样使用这些命令。

If you need the commands to coordinate with your terminal emulator (eg if you want to process the command in JS in your Node.js process), you can arrange that via a second environment variable containing eg a host/port to connect to.如果您需要命令与终端模拟器协调(例如,如果您想在 Node.js 进程中处理 JS 中的命令),您可以通过第二个环境变量进行安排,例如包含要连接的主机/端口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM