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)