autocomplete az commands in zsh on a mac


the following script assumes that you have the az command installed on your mac. if you have installed it using homebrew then it copies the auto-completion file to the location /opt/homebrew/etc/bash_completion.d/az already. all we have to do is to make it auto load on zsh startup. copy and paste the following command to do it. restart your zsh (cmd+q) after entering this command.

[[ -f /opt/homebrew/etc/bash_completion.d/az ]] && echo -e '\n# azure cli auto completion\nautoload -U +X bashcompinit && bashcompinit\nsource /opt/homebrew/etc/bash_completion.d/az' >> ~/.zshrc || echo 'autocomplete file not found'