Note: I previously blogged about displaying the current Kubernetes context using Oh-My-Posh v2. This post covers V3.
When I teach a Kubernetes class at Kubernetes Academy, people always ask me how I configured my Powershell prompt to display the cluster name of my current context. This is very useful if you're working with multiple clusters because it gives you constant feedback on the current K8s context.
1- Open a PowerShell prompt as an admin and install Oh-My_posh V3
Install-Module oh-my-posh -Scope CurrentUser
2- List the themes and identify the name of the one you like
3- Set the theme
Set-PoshPrompt -Theme [themeName]
4- Export the theme as a JSON file so you can make modifications to it and set the theme to that file
Export-PoshTheme -FilePath ~/.mytheme.omp.json -Format json Set-PoshPrompt -Theme ~/.mytheme.omp.json
5- Open your Powershell profile in Code (notepad will do if you don't have Code installed)
6- Import the Powershell modules, set a theme, and while you're at it, why not create aliases for kubectl and docker? 😀
Import-Module oh-my-posh Set-PoshPrompt -Theme ~/.mytheme.omp.json Set-Alias -Name k kubectl Set-Alias -Name d docker
7- From NerdFonts.com, install a font that supports ligatures and icons like Caskaydia Cove Nerd Font or Fira Code Nerd Font. These fonts are modified versions of the original Cascadia Code and Fira Code fonts.
8- Open the theme file in Code:
9- From the Oh-My-Posh Website, locate the segments menu, select the kubectl segment and insert it in the JSON file. Test and adjust to your liking.
10- In the Windows Terminal, click Settings and select the Powershell profile. Click on the Appearance tab and select the font you installed from NerdFonts.
That's it! Much simpler than it was using Oh-My-posh 2!
Bonus step! I'm also displaying an image in the bottom right section as a visual cue that reminds me that I'm in Powershell.
Open the Code Settings and select the profile you want to modify. Click on the Appearance tab and edit the background image settings.
Here are the pictures I use 😀
Azure Cloud Shell
Hope this helps!
Reference: Scott Hanselman's YouTube video