在Windows终端和执行命令中打开一个新的WSL2选项卡

发布于 2025-01-30 13:21:24 字数 164 浏览 3 评论 0原文

我在Windows终端上使用WSL2。我有一个需要在使用前端和后端的应用程序,然后才能使用它,因此每次我殿中打开终端窗口,导航到文件夹并运行命令时。 我想设置一个可以打开新标签,导航到文件夹并进行运行的别名。 我看到了Linux的建议,但是这些都没有使用WSL2在Windows终端上工作。有人有这种设置的经验吗?

I'm using WSL2 on Windows terminal. I have an app that needs front end and backend booted before it can be used, so every time I nave to open a terminal window, navigate to a folder and run a command.
I would like to set an alias that would open a new tab, navigate to a folder and do go run .
I saw suggestions for linux, but none of those work on Windows Terminal with WSL2. Anyone have experience with this setup?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

狠疯拽 2025-02-06 13:21:24

您可以为此创建个人资料。 (当然

{
    "commandline": "wsl.exe -d Ubuntu ping 8.8.8.8",
    "name": "backend",
    "startingDirectory": "\\\\wsl$\\Ubuntu\\home\\zadjii\\path\\to\\project",
},

,将ping 8.8.8.8替换为要运行的实际命令,用您使用的发行版的名称替换ubuntu),然后替换<< 实际路径,由double-backslashes界定。

代码> home \\ zadjii \\ path \\ to \\ project 带有您的 href =“ https://learn.microsoft.com/en-us/windows/terminal/terminal/command-palette” rel =“ nofollow noreferrer”>命令调色板一次打开​​多个命令:

{ 
    "name": "Run my project", 
    "command": { 
        "action": "multipleActions",
        "actions": [
            // Create a new tab with two panes
            { "action": "newTab", "tabTitle": "backend", "commandline": "wsl.exe -d Ubuntu run_my_backend", "startingDirectory": "\\\\wsl$\\Ubuntu\\home\\zadjii\\path\\to\\backend" },
            { "action": "splitPane", "tabTitle": "frontend", "commandline": "wsl.exe -d Ubuntu run_my_frontend", "startingDirectory": "\\\\wsl$\\Ubuntu\\home\\zadjii\\path\\to\\frontend" },
        ]
    }
}

请参阅href =“ https://learn.microsoft.com/en-us/windows/terminal/customize-settings/actions#run-multiple-actions” rel =“ nofollow noreferrer”> 乘法>乘法>乘法>乘法

You could create a profile for this. Something like

{
    "commandline": "wsl.exe -d Ubuntu ping 8.8.8.8",
    "name": "backend",
    "startingDirectory": "\\\\wsl$\\Ubuntu\\home\\zadjii\\path\\to\\project",
},

(of course, replace ping 8.8.8.8 with the actual command you want to run, replace Ubuntu with the name of the distro you're using, and replace home\\zadjii\\path\\to\\project with your actual path, delimited by double-backslashes.)

Now, if you wanted to get really crazy, you could create an action in the Command Palette which opened up multiple commands all at once:

{ 
    "name": "Run my project", 
    "command": { 
        "action": "multipleActions",
        "actions": [
            // Create a new tab with two panes
            { "action": "newTab", "tabTitle": "backend", "commandline": "wsl.exe -d Ubuntu run_my_backend", "startingDirectory": "\\\\wsl$\\Ubuntu\\home\\zadjii\\path\\to\\backend" },
            { "action": "splitPane", "tabTitle": "frontend", "commandline": "wsl.exe -d Ubuntu run_my_frontend", "startingDirectory": "\\\\wsl$\\Ubuntu\\home\\zadjii\\path\\to\\frontend" },
        ]
    }
}

see multipleActions

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文