# WSL, zsh and Powerlevel9k Beautiful command line interface for Windows 10 optimized for working with git and Kubernetes. ![WSL](https://gist.github.com/PashCracken/b6070359486ea651eed66a5e86567ebb/raw/6295adfe4fd0e2712b40f3a062ec7a2902c32657/WSL-with-zsh-and-powerlevel9k.png) ## Pre-reqs * Windows 10 * Windows Subsystem for Linux. I use Ubuntu 18.04 ## Install required nerd-fonts Install Powerline, Windows compatible font from this repo . You need to install version 1.2.0 since version 2.0.0 don't work with Windows. Download this asset . 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](https://gist.github.com/PashCracken/b6070359486ea651eed66a5e86567ebb/raw/6295adfe4fd0e2712b40f3a062ec7a2902c32657/X-WSL-font-options.png) ## Install and configure zsh ### Install zsh ```bash sudo apt install zsh ``` ### Install oh-my-zsh ```bash sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" ``` ### Install Powerlevel9k theme ```zsh git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k ``` ### Configure oh-my-zsh ```zsh nano ~/.zshrc ``` Open .zsh in nano and change/add the following settings ```zsh ZSH_THEME="powerlevel9k/powerlevel9k" 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 ```zsh curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.14.2/bin/linux/amd64/kubectl chmod +x ./kubectl sudo mv ./kubectl /usr/local/bin/kubectl ``` Add your colon delimited list of Kubernetes config files to KUBECONFIG env variable in .zshrc file ```zsh 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 ```zsh export KUBECONFIG="/mnt/c/dev/kubernetes/rnd-admin.conf:/mnt/c/Users/janl/.kube/config" ``` Add completion ```zsh echo "if [ $commands[kubectl] ]; then source <(kubectl completion zsh); fi" >> ~/.zshrc ``` Add shorthand alias for kubectl ```zsh nano ~/.zshrc ``` Add the following to the end of the .zshrc file ```zsh 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 ```zsh wget -q https://storage.googleapis.com/kubernetes-helm/helm-v2.14.0-linux-amd64.tar.gz tar xvzf helm-v2.14.0-linux-amd64.tar.gz sudo mv linux-amd64/helm /usr/local/bin helm init -c #Cleanup rm helm-v2.14.0-linux-amd64.tar.gz rm -r linux-amd64 ``` Add completion ```zsh echo "if [ $commands[helm] ]; then source <(helm completion zsh); fi" >> ~/.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 ```zsh 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 ``` Add completion ```zsh 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 rm -f ~/.zcompdump; compinit ``` Add kns and kctx aliases to your ~/.zshrc file ```zsh alias kns=kubens alias kctx=kubectx ``` Restart your WSL command prompt and you will have kubens and kubectx available with completion. ## Useful links * * * * * *