Oh My Zsh and Oh My Posh on Azure Cloud Shell

justinyoo

Justin Yoo

Posted on December 23, 2021

Oh My Zsh and Oh My Posh on Azure Cloud Shell

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.

GitHub logo justinyoo / oh-my-azure-cloud-shell

This provides an OPINIONATED collection of scripts to set up oh-my-zsh and oh-my-posh to your Azure Cloud Shell environment

Oh My Azure Cloud Shell

This provides an OPINIONATED collection of scripts to set up oh-my-zsh and oh-my-posh to your Azure Cloud Shell environment.

Getting Started

For oh-my-zsh

If you want to apply oh-my-zsh to your Azure Cloud Shell environment, follow the steps below:

  1. Open your Azure Cloud Shell.

  2. Make sure you are in the bash prompt. If you are in the PowerShell prompt, enter bash to switch the prompt.

  3. Clone this repository to your Azure Cloud Shell.

    git clone https://github.com/justinyoo/oh-my-azure-cloud-shell.git ~/oh-my-azure-cloud-shell
    Enter fullscreen mode Exit fullscreen mode
  4. Run the following commands and follow the instruction on the screen.

    ~/oh-my-azure-cloud-shell/install.sh
    Enter fullscreen mode Exit fullscreen mode

    The command above will install the Spaceship theme by default. If you prefer the Powerlevel10k theme, run the following command:

    # Turn on the clock feature
    ~/oh-my-azure-cloud-shell/install.sh -t p10k -c
    
    # Turn off the clock feature
    ~/oh-my-azure-cloud-shell/install.sh -t p10k
    Enter fullscreen mode Exit fullscreen mode
  5. Restart your Azure Cloud Shell.

  6. If you want to turn…

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.

  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.

  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.

  4. If you choose the Powerlevel10k theme, run the following command for further configuration.

  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.

  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:

  8. If you are with the Powerlevel10k theme and want to turn on or off the current time, run the following script:

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.

  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.

  3. Install plug-ins for oh-my-posh, like Terminal Icons.

  4. Create the $PROFILE file to run when initiating a PowerShell session.

  5. Run the following command to reload $PROFILE.

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

  7. If you are with the Powerlevel10k - Rainbow theme and want to turn on or off the current time, run the following script:

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.

💖 💪 🙅 🚩
justinyoo
Justin Yoo

Posted on December 23, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related