Skip to content

Commit

Permalink
fix(pwsh): add powershell shell
Browse files Browse the repository at this point in the history
pwsh is only added on newer versions of PowerShell which might not be
pre-installed in Windows 10
  • Loading branch information
aymanbagabas authored and maaslalani committed Nov 4, 2022
1 parent d3d1a74 commit b0c663c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 6 additions & 1 deletion shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const (
bash = "bash"
cmdexe = "cmd"
fish = "fish"
powershell = "pwsh"
powershell = "powershell"
pwsh = "pwsh"
zsh = "zsh"
)

Expand All @@ -30,6 +31,10 @@ var Shells = map[string]Shell{
Command: `clear; fish --login --private -C 'function fish_greeting; end' -C '%s'`,
},
powershell: {
Prompt: "Function prompt {Write-Host \"> \" -ForegroundColor Blue -NoNewLine; return \"`0\" }",
Command: ` clear; powershell -NoLogo -NoExit -Command 'Set-PSReadLineOption -HistorySaveStyle SaveNothing; %s'`,
},
pwsh: {
Prompt: "Function prompt {Write-Host \"> \" -ForegroundColor Blue -NoNewLine; return \"`0\" }",
Command: ` clear; pwsh -Login -NoLogo -NoExit -Command 'Set-PSReadLineOption -HistorySaveStyle SaveNothing; %s'`,
},
Expand Down
16 changes: 12 additions & 4 deletions tty_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@

package main

import "golang.org/x/sys/windows"
import (
"os/exec"

const defaultShell = powershell
"golang.org/x/sys/windows"
)

var defaultShell = cmdexe

func defaultShellWithArgs() []string {
major, _, _ := windows.RtlGetNtVersionNumbers()
if major >= 10 {
return []string{"powershell"}
if _, err := exec.LookPath("pwsh"); err == nil {
defaultShell = pwsh
} else {
defaultShell = powershell
}
}

return []string{"cmd"}
return []string{defaultShell}
}

0 comments on commit b0c663c

Please sign in to comment.