Enabling Azure CLI Bash Completion

📄
I've now started to use oh-my-posh (agnoster theme) instead of oh-my-zsh. If you install the Azure CLI using the bash script below, the bash completion will work for you straight away.

When using the Azure CLI in bash, did you know there's a way to tab complete commands, to save you having to memorise and type them manually? In this post, I'm going to show how you can enable bash completion for the Azure CLI.

I'm currently learning Linux (amongst other things), so am starting to force myself to use WSL a bit more these days. It works a treat, and it integrates well with Docker Desktop and Kubernetes 😎.

When I was looking around for tips on how to get my Windows Terminal configured, I found this blogpost. I think it's useful and well explained (thanks Pascal!). I followed it to a T, and I now have a nicer looking bash prompt!

One of the first things I installed was the Azure CLI. I tend to use that over PowerShell these days:

curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

I noticed something straight away - there was no tab completion.

If I use it in Azure Cloud Shell it's available there, so what do I need to do to get it working in my terminal?

Well, I first had to browse to /etc/bash_completion.d and make sure there was an azure-cli file. Check ✅

I then needed to go to my zsh config nano ~/.zshrc and add the below lines to the end of the file:

autoload bashcompinit && bashcompinit
source /etc/bash_completion.d/azure-cli

Once I saved and reloaded my terminal, I typed az acc, hit tab, and lo and behold it autocompleted for me. Success! 👍