How to enable command completion for Azure CLI in zsh?

It is possible to have completions for az in zsh.

  1. Get the completions for bash from the Azure CLI git repo and store this file somewhere your zsh startup script can find it: https://raw.githubusercontent.com/Azure/azure-cli/dev/az.completion

  2. Enable bash autocompletions in zsh if it's not enabled already:

    autoload -U +X bashcompinit && bashcompinit
    
  3. Enable the command completions for az:

    source /path/to/az.completion
    

The code snippets from step 2 and 3 can be added to a shell startup file (.zshrc or similar) to make the changes permanent.


Installed Az CLI on macOS Monterey with Homebrew I've used this commands in my ~/.zshrc file:

autoload -U +X bashcompinit && bashcompinit
source /opt/homebrew/etc/bash_completion.d/az

Autocompletion was deployed to another location.


Also, the bash completion file should already be installed on your system.

Look for /etc/bash_completion.d/azure-cli

If the file is there, you can skip step 1 in accepted answer and source that file directly.