azurezshazure-clizsh-completion

How to enable command completion for Azure CLI in zsh?


I've found hints at there being command completion available for bash[1] for the Azure CLI (az command), but I have not found any indication on how to install/enable that for zsh. Anyone know how to do that, if it is possible? I use oh-my-zsh, if that is relevant.

[1] https://learn.microsoft.com/en-us/cli/azure/get-started-with-azure-cli?view=azure-cli-latest#finding-commands


Solution

  • 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.