-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: update powershell completion for azure
- Loading branch information
1 parent
8722753
commit 121c6a8
Showing
1 changed file
with
26 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |