From a7dc936e0c8577a0beda3235485067eba8dbfc18 Mon Sep 17 00:00:00 2001 From: rsteube Date: Tue, 29 Oct 2024 15:54:49 +0100 Subject: [PATCH] powershell: support exe extension --- internal/shell/powershell/snippet.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/shell/powershell/snippet.go b/internal/shell/powershell/snippet.go index 8eb85b51..daa2be26 100644 --- a/internal/shell/powershell/snippet.go +++ b/internal/shell/powershell/snippet.go @@ -3,6 +3,7 @@ package powershell import ( "fmt" + "runtime" "github.com/carapace-sh/carapace/pkg/uid" "github.com/spf13/cobra" @@ -10,6 +11,10 @@ import ( // Snippet creates the powershell completion script. func Snippet(cmd *cobra.Command) string { + prefix := "# " + if runtime.GOOS == "windows" { + prefix = "" + } return fmt.Sprintf(`using namespace System.Management.Automation using namespace System.Management.Automation.Language Function _%v_completer { @@ -54,6 +59,7 @@ Function _%v_completer { $completions } -Register-ArgumentCompleter -Native -CommandName '%v' -ScriptBlock (Get-Item "Function:_%v_completer").ScriptBlock -`, cmd.Name(), uid.Executable(), uid.Executable(), cmd.Name(), cmd.Name()) +Register-ArgumentCompleter -Native -CommandName '%v' -ScriptBlock (Get-Item "Function:_%v_completer").ScriptBlock +%vRegister-ArgumentCompleter -Native -CommandName '%v.exe' -ScriptBlock (Get-Item "Function:_%v_completer").ScriptBlock +`, cmd.Name(), uid.Executable(), uid.Executable(), cmd.Name(), cmd.Name(), prefix, cmd.Name(), cmd.Name()) }