diff --git a/dotposh/Config/posh-completions/azure.ps1 b/dotposh/Config/posh-completions/azure.ps1 index 5b030a2..8f9df10 100644 --- a/dotposh/Config/posh-completions/azure.ps1 +++ b/dotposh/Config/posh-completions/azure.ps1 @@ -1,5 +1,5 @@ -# azure -if (Get-Module -ListAvailable -Name Azure -ErrorAction SilentlyContinue) { +# Azure Powershell +if (Get-Module -ListAvailable -Name Az -ErrorAction SilentlyContinue) { if ($($PSVersionTable.PSEdition) -like "Core") { if (-not (Get-Module -ListAvailable -Name "Az.Tools.Predictor" -ErrorAction SilentlyContinue)) { Write-Host "Installing PowerShell Module: Az.Tools.Predictor" -ForegroundColor "Green" @@ -7,4 +7,27 @@ if (Get-Module -ListAvailable -Name Azure -ErrorAction SilentlyContinue) { } Register-EngineEvent -SourceIdentifier PowerShell.OnIdle -MaxTriggerCount 1 -Action { Import-Module Az.Tools.Predictor -Global } | Out-Null } -} \ No newline at end of file +} + +# Azure CLI +if (Get-Command az -ErrorAction SilentlyContinue) { + Register-EngineEvent -SourceIdentifier PowerShell.OnIdle -MaxTriggerCount 1 -Action { + Register-ArgumentCompleter -Native -CommandName az -ScriptBlock { + param($commandName, $wordToComplete, $cursorPosition) + $completion_file = New-TemporaryFile + $env:ARGCOMPLETE_USE_TEMPFILES = 1 + $env:_ARGCOMPLETE_STDOUT_FILENAME = $completion_file + $env:COMP_LINE = $wordToComplete + $env:COMP_POINT = $cursorPosition + $env:_ARGCOMPLETE = 1 + $env:_ARGCOMPLETE_SUPPRESS_SPACE = 0 + $env:_ARGCOMPLETE_IFS = "`n" + $env:_ARGCOMPLETE_SHELL = 'powershell' + az 2>&1 | Out-Null + Get-Content $completion_file | Sort-Object | ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_, $_, "ParameterValue", $_) + } + Remove-Item $completion_file, Env:\_ARGCOMPLETE_STDOUT_FILENAME, Env:\ARGCOMPLETE_USE_TEMPFILES, Env:\COMP_LINE, Env:\COMP_POINT, Env:\_ARGCOMPLETE, Env:\_ARGCOMPLETE_SUPPRESS_SPACE, Env:\_ARGCOMPLETE_IFS, Env:\_ARGCOMPLETE_SHELL + } + } | Out-Null +}