Daniel's Tech Blog

Cloud Computing, Cloud Native & Kubernetes

Setting up Zsh with Oh My Zsh in Azure Cloud Shell

As you might know I recently switched jobs and now working primarily with a MacBook Pro at LeanIX. So, I am using the Zsh in my day to day work and wanted to have the same experience in Azure Cloud Shell as well. Per default the Azure Cloud Shell starts with a Bash environment, but also supports the Zsh.

I have written a shell script to set up Oh My Zsh, kubectx, kubens, krew and Linkerd in Azure Cloud Shell.

-> https://github.com/neumanndaniel/zsh-public

Beside that the following extensions for the Zsh get also installed zsh-autosuggestions and zsh-syntax-highlighting.

Afterwards the Zsh is your default environment, when starting Azure Cloud Shell. This is done via a trick through the .bashrc file calling the Zsh during the startup phase.

bash -c zsh

The reason for the workaround is that we cannot elevate permissions in Azure Cloud Shell. However, elevated permissions are required to execute chsh -s $(which zsh) correctly to change the default shell to Zsh.

Before you run the configureZsh.sh script, you must install the Powerline fonts.

-> https://github.com/powerline/fonts

Otherwise the Oh My Zsh themes are not displayed correctly. After the Powerline fonts installation go into your browser settings and change the fonts for the Monospace / fixed-width font display.

azurecloudshellzsh01azurecloudshellzsh02

As seen in the screenshots I am using the Meslo LG M for Powerline font.

Now start an Azure Cloud Shell session and clone the zsh-public repo.

git clone https://github.com/neumanndaniel/zsh-public.git

Execute the following commands to configure the Zsh in your Azure Cloud Shell session.

cd zsh-public/
chmod +x configureZsh.sh
./configureZsh.sh cloudshell

When you see [2019-07-29 21:44:41] Done. Please restart your Azure Cloud Shell session..., restart your Azure Cloud Shell session.

After the restart you are greeted by the Zsh and the robbyrussell theme.

azurecloudshellzsh03

If you have a kubeconfig credentials file in place, execute kubeon to get information about the current Kubernetes cluster and namespace context.

azurecloudshellzsh04

Furthermore, you can use kubectx and kubens to switch the context between clusters or namespaces.

azurecloudshellzsh05


Posted

in

WordPress Cookie Notice by Real Cookie Banner