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 at Kubernetes Academy Online.

Kubernetes Academy Online is Offering Self-Paced Online Video Training Courses with complete Hands-on Exercises. Available for AWS, Azure, DigitalOcean, Google Cloud Platform, and Linode. In English or French. Instructor-led Virtual Classes also available.

Courses info: KubernetesAcademy.online

🔥 Use the following code at checkout to save $10 on my self-paced courses. 1 offer per account.

$10 OFF Discount Code: GUYB-BLOG