Home WSL Bash customization using oh-my-posh
Post
Cancel

WSL Bash customization using oh-my-posh

In this post, I will explain how I tweaked my bash prompt in WSL using oh-my-posh. Below are the steps I followed to personalize my bash shell.

Install oh-my-posh.

1
2
sudo wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd64 -O /usr/local/bin/oh-my-posh
sudo chmod +x /usr/local/bin/oh-my-posh

Install a font that supports Powerline symbols.

  • Download the Caskaydia Cove Nerd Font. Extract the zip file, select them all and right-click to install.

  • Set the Caskaydia font on the settings of the windows terminal. Navigate to Windows Terminal –> Settings –> Ubuntu –> Appearance –> Font face. Then choose CaskaydiaCove Nerd Font and click save.

Get the custom configuration file.

1
2
mkdir ~/.poshthemes
git clone https://github.com/jobinjosem/oh-my-posh-custom-theme.git ~/.poshthemes

Configure ~/.bashrc

Add the following to ~/.bashrc (could be ~/.profile or ```` depending on your environment)

1
eval "$(oh-my-posh --init --shell bash --config '~/.poshthemes/mytheme.omp.json')"

Once added, reload your profile for the changes to take effect by running exec bash

customized_bash_shell I got my prompt looks like this after doing these steps.

Install kubectx + kubens

This will help to switch between different kubernetes clusters and namespaces, We need to download the kubectx and kubens binaries and install fuzzyfinder

1
2
3
4
5
6
7
8
9
10
11
12
wget -LO kubectx.tar.gz https://github.com/ahmetb/kubectx/releases/download/v0.9.4/kubectx_v0.9.4_linux_x86_64.tar.gz
tar -xvf kubectx.tar.gz
chmod +x kubectx
mv kubectx /usr/local/bin/

wget -LO kubens.tar.gz https://github.com/ahmetb/kubectx/releases/download/v0.9.4/kubens_v0.9.4_linux_x86_64.tar.gz
tar -xvf kubens.tar.gz
chmod +x kubens
mv kubens /usr/local/bin

git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install

Check for newer kubectx and kubens releases before downloading..

Create alias

To enhance your ability to seamlessly transition between different clusters and namespaces, it’s a wise approach to establish aliases. Incorporate the following aliases into your .bashrc file

1
2
3
alias x='kubectx'
alias n='kubens'
source ~/.bashrc

After adding these aliases, you’ll be able to use x to switch between clusters and n to switch between namespaces, making your interaction with Kubernetes more convenient. A list of available Kubernetes cluster contexts in your kubecfg will be shown.

Thanks for reading. Please do share your feedback.

-

Unveiling the Construction of This Blog