This blog post will show you how to add Azure CLI Tab Completion for Windows PowerShell.
Azure CLI (Command Line Interface) is a tool for managing Azure services. It’s designed to be easy and efficient for administrators and developers.
Tab completion, a feature in many command-line environments, automatically fills in partially typed commands. It increases productivity by reducing the amount of typing.
For Windows PowerShell users, enhancing the Azure CLI with tab completion isn’t built-in. You need to set it up manually. This setup improves command accuracy and speeds up your workflow. It’s a valuable addition for anyone regularly using Azure CLI.
Create a PowerShell profile
To get started, you must first create a PowerShell profile if it doesn’t exist. This profile file will hold custom scripts that enhance PowerShell’s functionality. Use the following script to create a profile:
if (!(Test-Path -Path $PROFILE)) {
New-Item -ItemType File -Path $PROFILE -Force
}
Then, open the profile and copy the Tab Completion code.
notepad $PROFILE
After creating or confirming the existence of your profile, the next step involves enhancing your Azure CLI experience.
Add Tab Completion Code
You’ll inject a script into this profile that enables tab completion. Here’s the script to add:
Register-ArgumentCompleter -Native -CommandName az -ScriptBlock {
param($commandName, $wordToComplete, $cursorPosition)
... [continues]
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
}
Once you save this script into your profile, restart PowerShell. Now, you can enjoy tab completion. Simply type ‘az’ followed by a space, press the tab key, and see the magic. This feature is sure to simplify your command executions in Azure CLI.
Related Articles
- Use PowerShell Remote Tabs to Connect to Multiple Servers From ISE
- Docker Command-Line Completion For The Windows Docker PowerShell Module
- Connect to OpenAI API GPT 4 With PowerShell