diff --git a/templates/completion.pwsh.gotmpl b/templates/completion.pwsh.gotmpl index 681d6fa..6c6dfab 100644 --- a/templates/completion.pwsh.gotmpl +++ b/templates/completion.pwsh.gotmpl @@ -69,7 +69,16 @@ Register-ArgumentCompleter -CommandName '{{ .CMDVarName }}' -ScriptBlock { # If the last parameter is complete (there is a space following it) # We add an extra empty parameter so we can indicate this to the go method. __{{ .CMDVarName }}_debug "Adding extra empty parameter" - $RequestComp="$RequestComp" + ' `"`"' + # PowerShell 7.2+ changed the way how the arguments are passed to executables, + # so for pre-7.2 or when Legacy argument passing is enabled we need to use + if ($PSVersionTable.PsVersion -lt [version]'7.2.0' -or + ($PSVersionTable.PsVersion -lt [version]'7.3.0' -and -not [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -or + (($PSVersionTable.PsVersion -ge [version]'7.3.0' -or [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -and + $PSNativeCommandArgumentPassing -eq 'Legacy')) { + $RequestComp="$RequestComp" + ' `"`"' + } else { + $RequestComp="$RequestComp" + ' ""' + } } __{{ .CMDVarName }}_debug "Calling $RequestComp"