修复: 同事机器无 pwsh 启动失败 0x80070002

- 探测优先 pwsh (PS7),找不到回退 powershell (PS5,Windows 自带)
- 脚本仅用兼容语法 (Write-Host/cd),PS5 可直接运行
This commit is contained in:
lxy
2026-07-06 16:53:49 +08:00
parent ec2603444d
commit 043a7d9227
+10 -1
View File
@@ -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)