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
zsh-autocomplete adds real-time type-ahead autocompletion to Zsh. Find as you type, then press Tab to insert the top completion, Shift Tab to insert the bottom one, or ↓ / PgDn to select another completion.
for ZSH usersZsh can handle bash completions functions. The latest development version of zsh has a function bashcompinit, that when run will allow zsh to read bash completion specifications and functions.
On macOS completions are stored in /usr/share/zsh/5.3/functions (replace the 5.3 with 5.7. 1 in Catalina). This directory stores many functions used with zsh and is in the default fpath . All the files in that directory that start with an underscore _ contain the completion definitions command.
How to sign into the Azure CLI. Before using any Azure CLI commands with a local install, you need to sign in with az login. Run the login command. If the CLI can open your default browser, it will initiate authorization code flow and open the default browser to load an Azure sign-in page.
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.
It is possible to have completions for az
in zsh.
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
Enable bash autocompletions in zsh if it's not enabled already:
autoload -U +X bashcompinit && bashcompinit
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With