How to Install Azure CLI Auto Completion Plugin

Enes Turan
3 min readMar 27, 2023

Are you tired of typing out lengthy commands every time you use the Azure CLI? Fortunately, there is a solution — the Azure CLI auto completion plugin. In this article, we will guide you through the steps to install and enable the plugin, which will save you time and effort by completing subcommands, flags, and resource names for your commands.

Install Azure CLI

Before we can install the plugin, you need to have brew and zsh installed on your system. If you are using macOS, you can install the Azure CLI by running the following command in your terminal:

brew install azure-cli

This will install the Azure CLI on your system.

Enable Auto Completion Plugin

After you have installed the Azure CLI, the Auto Completion Plugin will be included, but it needs to be enabled in order to use it. You can find the plugin in the Azure CLI repository at https://github.com/Azure/azure-cli/blob/dev/az.completion.

To enable the plugin, you will need to add a command to your ~/.zshrc file. The command you need to add may vary depending on your Azure CLI version. If you’re unsure what version you have installed, you can find out by running the following command in your terminal:

az --version

This will display the version number of your Azure CLI.

Next, you need to find the path to the Azure CLI Auto Completion Plugin file. The path is typically in this format for M1 macOS machines:

/opt/homebrew/Cellar/azure-cli/<version>/etc/bash_completion.d/az

Where <version> is the version number of your Azure CLI.

You can learn the path to the Azure CLI Auto Completion Plugin file by running the following command in your terminal:

find /opt/homebrew -name az

This will search for the az file in your Azure CLI directory and display the path to the file. Make a note of the path, as you will need it in the next step.

Once you have the path to the file, you can enable the plugin by adding the following command to your ~/.zshrc file:

source <path to az completion file>

Note that the path to the file may be different depending on your version of the Azure CLI. Make sure you replace <path to az file> with the actual path to the file on your system.

For example the following command should work for version 2.46.0 and it is the latest version currently:

source /opt/homebrew/Cellar/azure-cli/2.46.0/etc/bash_completion.d/az

Ensure cross-compatibility between bash and zsh script

If you encounter an error when restarting, you may need to add the following line to your ~/.zshrc file before the script loading to ensure cross compatibility between bash and zsh script:

autoload -U +X bashcompinit && bashcompinit

This will ensure that the plugin is compatible with both bash and zsh.

By following these steps, you should now have the Azure CLI auto completion plugin installed and enabled, which will complete your commands for you, saving you time and effort. Now, you can focus on more important tasks without worrying about typing out lengthy commands.

Sign up to discover human stories that deepen your understanding of the world.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Responses (1)

Write a response

Thank you for your post. I followed all your steps and I no get the following error:
complete:13: command not found: compdef
This is my .zshrc
# ~/.zshrc
eval "$(starship init zsh)"
autoload -U +X bashcompinit && bashcompinit...