Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save naturalkei/8093fe95364db0490dcbdb187f90c719 to your computer and use it in GitHub Desktop.
Save naturalkei/8093fe95364db0490dcbdb187f90c719 to your computer and use it in GitHub Desktop.
WSL, zsh and Powerlevel10k

WSL, zsh and Powerlevel10k

Beautiful command line interface for Windows 10 optimized for working with git and Kubernetes.

NB Guide has been updated to use Homebrew

WSL

Pre-reqs

  • Windows 10
  • Windows Subsystem for Linux. I use Ubuntu 18.04

Homebrew

The rest of this guide will use Homebrew https://brew.sh/ to install most of the tools

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Install required nerd-fonts

Install Powerline, Windows compatible font from this repo https://github.com/ryanoasis/nerd-fonts. You need to install version 1.2.0 since version 2.0.0 don't work with Windows.

Download this asset https://github.com/ryanoasis/nerd-fonts/releases/download/v1.2.0/DejaVuSansMono.zip. Unzip file and install the DejaVu Sans Mono for Powerline Nerd Font Complete Mono Windows Compatible.ttf font by right-clicking on the file and select install.

Change WSL font

Open the WSL options and change font to DejaVuSansMonoPowerline NF DejaVuSansMonoPowerline NF

Install and configure zsh

Install zsh

sudo apt install zsh

Install oh-my-zsh

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Install Powerlevel10k theme

git clone https://github.com/romkatv/powerlevel10k.git ~/.oh-my-zsh/custom/themes/powerlevel10k

Configure oh-my-zsh

nano ~/.zshrc

Open .zsh in nano and change/add the following settings

ZSH_THEME="powerlevel10k/powerlevel10k"
POWERLEVEL9K_MODE='nerdfont-complete'
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir dir_writable vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status kubecontext time)
POWERLEVEL9K_PROMPT_ON_NEWLINE=true
# If you have installed Windows 10 1903 then you can skip the next line
POWERLEVEL9K_COLOR_SCHEME='light'

Restart your WSL command prompt and it will look great

Kubernetes tools

kubectl

brew install kubernetes-cli

Add your colon delimited list of Kubernetes config files to KUBECONFIG env variable in .zshrc file

nano ~/.zshrc

Add the follwing at the end of the file and change paths to your config files. I choose to point them to my Windows k8s config files that I also use in Powershell

export KUBECONFIG="/mnt/c/dev/kubernetes/rnd-admin.conf:/mnt/c/Users/janl/.kube/config"

Run command to add completion

echo "source <(kubectl completion zsh)" >> ~/.zshrc

Add shorthand alias for kubectl

nano ~/.zshrc

Add the following to the end of the .zshrc file

alias k=kubectl
complete -F __start_kubectl k

Restart your WSL command prompt and you will see the Kubernetes context and have code completion for both kubectl and the alias k

helm

brew install helm

Run command to add completion

echo "source <(helm completion zsh)" >> ~/.zshrc

Restart your WSL command prompt and you will have helm command with completion

kubens and kubectx

Tools for fast switching between clusters and namespaces

sudo git clone https://github.com/ahmetb/kubectx /opt/kubectx
sudo ln -s /opt/kubectx/kubectx /usr/local/bin/kubectx
sudo ln -s /opt/kubectx/kubens /usr/local/bin/kubens

Run commands to add completion

mkdir -p ~/.oh-my-zsh/completions
chmod -R 755 ~/.oh-my-zsh/completions
ln -s /opt/kubectx/completion/kubectx.zsh ~/.oh-my-zsh/completions/_kubectx
ln -s /opt/kubectx/completion/kubens.zsh ~/.oh-my-zsh/completions/_kubens

Add kns and kctx aliases at the end of your ~/.zshrc file Also add the rm -f ~/.zcompdump; compinit to fix an issue with completion for kubens and kubectx

alias kns=kubens
alias kctx=kubectx
rm -f ~/.zcompdump; compinit

Restart your WSL command prompt and you will have kubens and kubectx available with completion.

k9s

The best CLI for managing Kubernetes https://k9scli.io/

brew install derailed/k9s/k9s

Useful links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment