修复: 同事机器无 pwsh 启动失败 0x80070002
- 探测优先 pwsh (PS7),找不到回退 powershell (PS5,Windows 自带) - 脚本仅用兼容语法 (Write-Host/cd),PS5 可直接运行
This commit is contained in:
+10
-1
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user