From a6a563d6568e4c52623973fd7db48572d2aa973b Mon Sep 17 00:00:00 2001 From: Mavaddat Javid <5055400+mavaddat@users.noreply.github.com> Date: Mon, 12 Jun 2023 10:46:19 -0400 Subject: [PATCH] =?UTF-8?q?completers=20=E2=88=80x=E2=88=88=20{cmds,=20ali?= =?UTF-8?q?ases}=20in=20powershell=5Fcompletions.go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pwsh completers ∀x∈ {cmds, aliases} --- powershell_completions.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/powershell_completions.go b/powershell_completions.go index 177d2755..94efa4a5 100644 --- a/powershell_completions.go +++ b/powershell_completions.go @@ -278,8 +278,16 @@ filter __%[1]s_escapeStringWithSpecialChars { } } +# Enumerate the cmds for %[1]s (set by System.Environment) +$available%[2]s = Get-Command -Name '%[1]s' -All -ErrorAction SilentlyContinue -Register-ArgumentCompleter -CommandName '%[1]s' -ScriptBlock $__%[2]sCompleterBlock +# Enumerate set aliases for %[1]s (set by user) +$__%[2]sAliases = @() +foreach($__%[2]sCmd in $available%[2]s){ + $__%[2]sAliases += Get-Alias | Where-Object { $_.Definition -eq ($__%[2]sCmd | Resolve-Path) } +} +# Register args completer for all cmds and aliases +Register-ArgumentCompleter -CommandName ([array]$available%[2]s.Name + [array]$__%[2]sAliases.Name) -ScriptBlock $__%[2]sCompleterBlock `, name, nameForVar, compCmd, ShellCompDirectiveError, ShellCompDirectiveNoSpace, ShellCompDirectiveNoFileComp, ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs, ShellCompDirectiveKeepOrder, activeHelpEnvVar(name)))