7 min read

Oh My Azure Cloud Shell

Justin Yoo

You likely heard of or currently use oh-my-zsh for your terminal on Linux or Mac, or WSL on Windows. It might also be possible to have heard of or currently use oh-my-posh for your PowerShell. Azure offers Azure Cloud Shell service, which uses both Bash Shell and PowerShell by default. Therefore, if you want either oh-my-zsh or oh-my-posh, or both, you should configure it by yourself.

Throughout this post, I'm going to show how to configure your shell environment for both.

This GitHub repository provides the working shell script source for your reference.

For oh-my-zsh

Let's configure oh-my-zsh on your Azure Cloud Shell. Make sure that you see the Bash Shell prompt. If not, enter the bash command to switch your prompt to Bash.

  1. Install oh-my-zsh.

    sh -c "$(curl -fsSL \
    https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  2. Install plug-ins for oh-my-zsh. Although there are many good plug-ins, this post will install the three popular ones – zsh-completions, zsh-syntax-highlighting and zsh-autosuggestions. If you want more plug-ins, follow the steps below.

    # Plugin: zsh-completions
    git clone https://github.com/zsh-users/zsh-completions.git \
    ~/.oh-my-zsh/custom/plugins/zsh-completions
    # Plugin: zsh-syntax-highlighting
    git clone https://github.com/zsh-users/zsh-syntax-highlighting.git \
    ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
    # Plugin: zsh-autosuggestions
    git clone https://github.com/zsh-users/zsh-autosuggestions.git \
    ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
  3. Install themes for oh-my-zsh. It's totally up to you which theme you're going to pick, but this post chooses either Spaceship or Powerlevel10k.

    # Theme: Spaceship
    git clone https://github.com/spaceship-prompt/spaceship-prompt.git \
    ~/.oh-my-zsh/custom/themes/spaceship-prompt --depth=1
    ln -s ~/.oh-my-zsh/custom/themes/spaceship-prompt/spaceship.zsh-theme \
    ~/.oh-my-zsh/custom/themes/spaceship.zsh-theme
    # Theme: Powerlevel10k
    git clone https://github.com/romkatv/powerlevel10k.git \
    ~/.oh-my-zsh/custom/themes/powerlevel10k --depth=1
    ln -s ~/.oh-my-zsh/custom/themes/powerlevel10k/powerlevel10k.zsh-theme \
    ~/.oh-my-zsh/custom/themes/powerlevel10k.zsh-theme
  4. If you choose the Powerlevel10k theme, run the following command for further configuration.

    p10k configure
  5. As mentioned above, Azure Cloud Shell uses Bash Shell by default. Unfortunately, you can't run the chsh -s $(which zsh) command because sudo is not allowed. Therefore, update your .bashrc like below, as a workaround.

    bash -c zsh
  6. Once everything so far is done, restart Azure Cloud Shell. Alternatively, run the command, source .bashrc. Then, you will have the oh-my-zsh applied shell prompt.
  7. If you want to run all steps above in just one command, run the following:

    # Download the GitHub repository
    git clone https://github.com/justinyoo/oh-my-azure-cloud-shell.git ~/oh-my-azure-cloud-shell
    # Install oh-my-zsh with the theme of "Spaceship"
    ~/oh-my-azure-cloud-shell/install.sh -t spaceship
    # Install oh-my-zsh with the theme of "Powerlevel10k"
    ~/oh-my-azure-cloud-shell/install.sh -t p10k
  8. If you are with the Powerlevel10k theme and want to turn on or off the current time, run the following script:

    # Turn on the clock feature
    ~/oh-my-azure-cloud-shell/switch-p10k-clock.sh -c
    # Turn off the clock feature
    ~/oh-my-azure-cloud-shell/switch-p10k-clock.sh

Now, your Azure Cloud Shell starts using oh-my-zsh.

For oh-my-posh

Let's configure oh-my-posh on your Azure Cloud Shell this time. Make sure that you see the PowerShell prompt. If not, enter the pwsh command to switch your prompt to PowerShell.

  1. Install oh-my-posh.

    Install-Module oh-my-posh -Scope CurrentUser -Repository PSGallery -Force
    Import-Module oh-my-posh -Scope Local -Force
  2. Install themes for oh-my-posh. Again, it's totally up to you which theme you're going to pick, but this post chooses either Spaceship or Powerlevel10k - Rainbow.

    # Theme: Spaceship
    Set-PoshPrompt -Theme spaceship
    # Theme: Powerlevel10k - Rainbow
    Set-PoshPrompt -Theme powerlevel10k_rainbow
  3. Install plug-ins for oh-my-posh, like Terminal Icons.

    Install-Module Terminal-Icons -Scope CurrentUser -Repository PSGallery -Force
    Import-Module Terminal-Icons -Scope Local -Force
  4. Create the $PROFILE file to run when initiating a PowerShell session.

    if (!(Test-Path -Path $PROFILE)) {
    New-Item -ItemType File -Path $PROFILE -Force
    }
    # Theme: Spaceship
    Write-Output "
    Set-PoshPrompt -Theme spaceship
    Import-Module Terminal-Icons -Scope Local -Force
    " | Out-File -FilePath $PROFILE -Encoding UTF8 -Append -Force
    # Theme: Powerlevel10k - Rainbow
    Write-Output "
    Set-PoshPrompt -Theme powerlevel10k_rainbow
    Import-Module Terminal-Icons -Scope Local -Force
    " | Out-File -FilePath $PROFILE -Encoding UTF8 -Append -Force
  5. Run the following command to reload $PROFILE.

    . $PROFILE
  6. If you want to run all steps above in just one command, run the following:

    # Download the GitHub repository
    git clone https://github.com/justinyoo/oh-my-azure-cloud-shell.git `
    ~/oh-my-azure-cloud-shell
    # Install oh-my-zsh with the theme of "Spaceship"
    ~/oh-my-azure-cloud-shell/install.ps1 -Theme spaceship
    # Install oh-my-zsh with the theme of "Powerlevel10k - Rainbow"
    ~/oh-my-azure-cloud-shell/install.ps1 -Theme p10k
  7. If you are with the Powerlevel10k - Rainbow theme and want to turn on or off the current time, run the following script:

    # Turn on the clock feature
    ~/oh-my-azure-cloud-shell/switch-p10k-clock.ps1 -WithClock
    # Turn off the clock feature
    ~/oh-my-azure-cloud-shell/switch-p10k-clock.ps1

Now, your Azure Cloud Shell starts using oh-my-zsh.


So far, I've walked through how to configure either oh-my-zsh or oh-my-posh, or both. With both configurations, you will be able to extend your local shell scripting experiences to Azure Cloud Shell.