WSL prompt: How to display your current Kubernetes context
In a previous post, I explained how to display the current Kubernetes context on the command prompt by setting Powerline in Powershell. If you installed WSL and a Linux distro like Ubuntu, you might also want to do that.
If not already done, install the Windows Terminal and a font that supports ligatures like Cascadia Code PL or Fira Code.
1- Windows Terminal will detect your WSL distro automatically, simply select it to open a new Terminal window.
2- Install Go and Powerline-GO
sudo apt install golang-go
go get -u github.com/justjanne/powerline-go
3- Enable Powerline-Go by editing the bash config file in VS Code
code ~/.bashrc
4- Add the following. Beware that GOPATH may already exist. Note that one of the modules that will be used is called kube. It will parse your kubeconfig file to extract the current context.
GOPATH=$HOME/go
function _update_ps1() {
PS1="$($GOPATH/bin/powerline-go -modules "venv,user,host,ssh,kube,cwd,perms,git,hg,jobs,exit,root" -error $?)"
}
if [ "$TERM" != "linux" ] && [ -f "$GOPATH/bin/powerline-go" ]; then
PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
fi
5- In the Windows Terminal, edit the settings. This will launch your editor, in my case, Code.
6- Locate the distro section and set the fontFace to Fira Code or Cascadia Code PL.
"guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",
"hidden": false,
"name": "Ubuntu-20.04",
"cursorColor" : "#FFFFFF",
"cursorShape" : "filledBox",
"fontFace" : "Fira Code",
"fontSize" : 12,
"backgroundImage": "C:/Users/guyba/Pictures/Terminal/Tux.png",
"backgroundImageOpacity": 0.5,
"backgroundImageStretchMode": "none",
"backgroundImageAlignment": "bottomRight",
"useAcrylic" : false,
"source": "Windows.Terminal.Wsl"
References:
Windows Terminal Documentation
Powerline-Go Documentation
Learn Docker and Kubernetes

Like this blog post? I also teach Docker and Kubernetes online virtual classes at Kubernetes Academy.
Kubernetes Academy offers instructor led training workshop-style on Docker containers and Kubernetes for web developers, DevOps specialists, I.T. Pros.
Courses info: LearnK8s.ca