Windows终端:打开多个窗格并执行指定的命令 [英] Windows terminal: open multiple panes and execute specified command

查看:662
本文介绍了Windows终端:打开多个窗格并执行指定的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近下载了新的 Windows Terminal 。我已经创建了用于打开多个窗格的快捷方式(工作正常)。但是,我正在尝试为各个窗格执行命令。

I recently downloaded the new Windows Terminal. I have created the shortcut for opening the multiple panes(which is working fine). However, I am trying to execute a command for the respective pane.

wt -d <path> -c "cls && php artisan serve" ; 
   split-pane -p "Command Prompt" -H -d <path> -c "npm run watch"

我用Google搜索解决方案,但没有运气。

I googled for the solution but no luck.

这是否有可能..?

推荐答案

简短的答案是:是的,有可能,但这是一种解决方法。

挑战


  1. wt.exe 当前没有命令行选项,可从分割窗格命令c>

  2. wsl.exe (运行您的默认shell,如bash)当前不支持使用不带命令的命令打开shell在命令运行后立即退出外壳。

  1. wt.exe does not currently have a command line option to execute a command from a split-pane
  2. wsl.exe (which runs your default shell such as bash) does not currently support opening a shell with a command without exiting the shell right after the command is run.

解决方法

要绕开第一个挑战,我们可以启动一个自定义配置文件,该配置文件通过键值对(在设置json中,中的 wsl.exe 来执行命令)。命令行: wsl.exe'命令转到此处

To get around the first challenge we can launch a custom profile that executes the command via wsl.exe in the key value pair (in settings json) "commandline": "wsl.exe 'commands go here"

要解决第二个挑战,我们需要通过 powershell.exe 通过 wsl.exe'命令转到此处',因为Powershell的 -NoExit 选项将在执行命令后保持外壳打开。因此,例如,如果您想使用命令 watch ps wsl.exe (您的Linux shell)的外壳>,则自定义配置文件中的行将如下所示:

To get around the second challenge we need to execute the wsl.exe 'commands go here' via powershell.exe because Powershell has a -NoExit option which will keep the shell open after the command is executed. So for example if you wanted to open a shell that runs wsl.exe (your linux shell) with the command watch ps then the line in the custom profile would look like this:

commandline: powershell.exe -NoExit -Command wsl.exe watch ps

解决方案:

在Windows Terminal中创建配置文件 settings.json 您要运行的每个命令。每个配置文件应该具有唯一的 guid ,您可以通过运行命令 [guid] :: NewGuid()。因此,运行命令 watch ps 的配置文件看起来像这样:

Create a profile in Windows Terminal settings.json for each command you want to run. Each profile should have a unique guid that you can generate in Powershell by running the command [guid]::NewGuid(). So the profile to run the command watch ps would look something like this:

            {
                "guid": "{b7041a85-5613-43c0-be35-92d19002404f}",
                "name": "watch_ps",
                "commandline": "powershell.exe -NoExit -Command wsl.exe watch ps",
                "hidden": false,
                "colorScheme": "One Half Dark"
            },

现在您可以在Windows终端中打开一个带有两个窗格的选项卡,右侧窗格将运行命令 watch ps ,外壳将保持打开状态。在您的快捷方式(或从命令行)中输入以下代码行,其中选项 -p 的值等于您创建的配置文件的值。您打开的每个其他窗格都需要一个配置文件,该配置文件中包含您要运行的命令。

Now you can open a tab in windows terminal with two panes, the pane on the right will run the command watch ps and the shell will stay open. Put something like the below line of code in your shortcut (or from the command line) where the value of the option -p is equal to the value of the profile you created. Each additional pane you open will need a profile that has the command you want to run in it.

wt split-pane -p watch_ps

这篇关于Windows终端:打开多个窗格并执行指定的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆