Skip to content

Commit

Permalink
✨ feat: update powershell completion for azure
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquindev committed Jan 11, 2025
1 parent 8722753 commit 121c6a8
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions dotposh/Config/posh-completions/azure.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
# 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"
Install-Module -Name "Az.Tools.Predictor" -AcceptLicense -Scope CurrentUser -Force
}
Register-EngineEvent -SourceIdentifier PowerShell.OnIdle -MaxTriggerCount 1 -Action { Import-Module Az.Tools.Predictor -Global } | Out-Null
}
}
}

# 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
}

0 comments on commit 121c6a8

Please sign in to comment.