From 043a7d92270ddd007a0fed4ed09b60fdd01a1a31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=9D=E5=B0=98?= <237809796@qq.com> Date: Mon, 6 Jul 2026 16:53:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20=E5=90=8C=E4=BA=8B?= =?UTF-8?q?=E6=9C=BA=E5=99=A8=E6=97=A0=20pwsh=20=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=200x80070002?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 探测优先 pwsh (PS7),找不到回退 powershell (PS5,Windows 自带) - 脚本仅用兼容语法 (Write-Host/cd),PS5 可直接运行 --- internal/launch.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/launch.go b/internal/launch.go index c468af9..8ff940c 100644 --- a/internal/launch.go +++ b/internal/launch.go @@ -105,6 +105,15 @@ func (a SessionAction) bashScript() string { // --- 启动辅助 --- +// powershellExe 返回可用的 PowerShell 可执行文件名:优先 pwsh (PS7),找不到则回退 powershell (PS5,Windows 自带)。 +// 脚本只用 $Host.UI.RawUI、Write-Host、cd 等兼容语法,PS5 也能跑。 +func powershellExe() string { + if _, err := exec.LookPath("pwsh"); err == nil { + return "pwsh" + } + return "powershell" +} + func launchInWtWithTitle(dir, tabTitle, script string) { encoded := encodePSCommand(script) color := fmt.Sprintf("#%02X%02X%02X", randRange(80, 255), randRange(80, 255), randRange(80, 255)) @@ -112,7 +121,7 @@ func launchInWtWithTitle(dir, tabTitle, script string) { if tabTitle != "" { args = append(args, "--title", tabTitle) } - args = append(args, "pwsh", "-NoExit", "-EncodedCommand", encoded) + args = append(args, powershellExe(), "-NoExit", "-EncodedCommand", encoded) cmd := exec.Command("wt.exe", args...) if err := cmd.Start(); err != nil { log.Printf("[u-tabs] launch fail: %v", err)