Skip to content

Commit

Permalink
feat: enable Windows PowerShell
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Jun 28, 2024
1 parent 3ec2945 commit 6f9aa33
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var (
printOutput bool

initCmd = &cobra.Command{
Use: "init [bash|zsh|fish|pwsh|cmd|nu|tcsh|xonsh] --config ~/.aliae.yaml",
Use: "init [bash|zsh|fish|pwsh|powershell|cmd|nu|tcsh|xonsh] --config ~/.aliae.yaml",
Short: "Initialize your shell and config",
Long: `Initialize your shell and config.
Expand All @@ -22,6 +22,7 @@ See the documentation to initialize your shell: https://aliae.dev/docs/setup/she
"zsh",
"fish",
"pwsh",
"powershell",
"cmd",
"nu",
"tcsh",
Expand Down
4 changes: 2 additions & 2 deletions src/core/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
)

func Init(configPath, sh string, printOutput bool) string {
if sh == shell.PWSH && !printOutput {
return fmt.Sprintf("(@(& aliae init pwsh --config=%s --print) -join \"`n\") | Invoke-Expression", configPath)
if shell.IsPowerShell(sh) && !printOutput {
return fmt.Sprintf("(@(& aliae init %s --config=%s --print) -join \"`n\") | Invoke-Expression", sh, configPath)
}

context.Init(sh)
Expand Down
2 changes: 1 addition & 1 deletion src/shell/aliae.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (a *Alias) string() string {
switch context.Current.Shell {
case ZSH, BASH:
return a.zsh().render()
case PWSH:
case PWSH, POWERSHELL:
return a.pwsh().render()
case NU:
return a.nu().render()
Expand Down
2 changes: 1 addition & 1 deletion src/shell/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (e *Echo) String() string {
return e.zsh().render()
case NU:
return e.nu().render()
case PWSH:
case PWSH, POWERSHELL:
return e.pwsh().render()
case CMD:
return e.cmd().render()
Expand Down
2 changes: 1 addition & 1 deletion src/shell/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (e *Env) string() string {
switch context.Current.Shell {
case ZSH, BASH:
return e.zsh().render()
case PWSH:
case PWSH, POWERSHELL:
return e.pwsh().render()
case NU:
return e.nu().render()
Expand Down
2 changes: 1 addition & 1 deletion src/shell/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (p *Path) string() string {
switch context.Current.Shell {
case ZSH, BASH:
return p.zsh().render()
case PWSH:
case PWSH, POWERSHELL:
return p.pwsh().render()
case NU:
return p.nu().render()
Expand Down
7 changes: 6 additions & 1 deletion src/shell/pwsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
)

const (
PWSH = "pwsh"
PWSH = "pwsh"
POWERSHELL = "powershell"

AllScope Option = "AllScope"
Constant Option = "Constant"
Expand All @@ -24,6 +25,10 @@ const (
ScriptScope Option = "Script"
)

func IsPowerShell(shell string) bool {
return shell == PWSH || shell == POWERSHELL
}

func (a *Alias) pwsh() *Alias {
// PowerShell can't handle aliases with switches
// unlike unix shells do so we wrap those in a function
Expand Down

0 comments on commit 6f9aa33

Please sign in to comment.