From 6f9aa33e77c76dab5ddb2ba3085126c6beabfbe8 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Thu, 27 Jun 2024 13:59:45 +0200 Subject: [PATCH] feat: enable Windows PowerShell --- src/cli/init.go | 3 ++- src/core/init.go | 4 ++-- src/shell/aliae.go | 2 +- src/shell/echo.go | 2 +- src/shell/env.go | 2 +- src/shell/path.go | 2 +- src/shell/pwsh.go | 7 ++++++- 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/cli/init.go b/src/cli/init.go index 5bdf75c..7c8fbe3 100644 --- a/src/cli/init.go +++ b/src/cli/init.go @@ -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. @@ -22,6 +22,7 @@ See the documentation to initialize your shell: https://aliae.dev/docs/setup/she "zsh", "fish", "pwsh", + "powershell", "cmd", "nu", "tcsh", diff --git a/src/core/init.go b/src/core/init.go index 821184f..e05e1fe 100644 --- a/src/core/init.go +++ b/src/core/init.go @@ -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) diff --git a/src/shell/aliae.go b/src/shell/aliae.go index d2ca8cb..c18f436 100644 --- a/src/shell/aliae.go +++ b/src/shell/aliae.go @@ -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() diff --git a/src/shell/echo.go b/src/shell/echo.go index 2dff1b0..be667d6 100644 --- a/src/shell/echo.go +++ b/src/shell/echo.go @@ -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() diff --git a/src/shell/env.go b/src/shell/env.go index a61480e..79bd618 100644 --- a/src/shell/env.go +++ b/src/shell/env.go @@ -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() diff --git a/src/shell/path.go b/src/shell/path.go index dba3c06..79c8cb4 100644 --- a/src/shell/path.go +++ b/src/shell/path.go @@ -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() diff --git a/src/shell/pwsh.go b/src/shell/pwsh.go index 68afe20..2c6f95d 100644 --- a/src/shell/pwsh.go +++ b/src/shell/pwsh.go @@ -8,7 +8,8 @@ import ( ) const ( - PWSH = "pwsh" + PWSH = "pwsh" + POWERSHELL = "powershell" AllScope Option = "AllScope" Constant Option = "Constant" @@ -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