Customizing WSL2 on Windows with screenfetch and oh-my-zsh
Image from Unsplash

Customizing WSL2 on Windows with screenfetch and oh-my-zsh

Setting up screenfetch and oh-my-zsh for use in WSL2 and Windows Terminal

Windows Subsystem for Linux or WSL i a great way to have a Linux environment easily accessible from your development environment on Windows. With latest Windows10 May 2020 update 2020H1 WSL got a major update WSL2 which enables even more fluent integration of Linux kernel into Windows10.

I will assume that you are already using WSL2 and you are familiar with initial setup of it on Window10. If you are new to WSL I recommend you check Windows documentation especially Install WSL & update to WSL 2 and Comparing WSL 1 and WSL 2 which should help you getting started with WSL.

Windows Terminal is another component that I will use in this article, so make sure you have it installed on your Windows10 from Windows Store. It is a lot more convenient having all your consoles in a single window with multiple tabs that having multiple windows scattered around your desktop plus it allows great level of customizations. You can also install it directly from Windows Store.

In this article I will use Ubuntu 20.04 LTS as WSL OS. You can find links to both Linux distro for WSL and Windows Terminal below: 

If you already have any WSL distro installed, Windows Terminal will recognize it and add it to it's configuration so you have it's profile already present in the profiles list in the terminal window.

Wndows Terminal

Setting up screenfetch 

For various reasons you may need to capture or share your distro and hardware info. Mostly th case is trouble shooting an issue, but it may also be to easily distinct among multiple distros you may have installed for WSL. 

You can always use various commands to fetch this data, but an easier and more elegant way is to have this shown to you on startup. This is where screenfetch comes into play. It is not the only way to show your environment info, but I find it very elegant will all the necessary info, both hardware and software.

Before we install screenfetch, make sure you have all the packages updated.

sudo apt update && sudo apt-get update
    

Now when packages are updated we can install screenfetch package

sudo apt-get install screenfetch -y
    

Finally, once you have package installed we need to update bash profile. You can use any text editor you have available. I prefer nano but vim or anything else you have or prefer is good enough.

nano ~/.bashrc
    

All you have to to is to navigate to the end of the file and add new line with a call to screenfetch.

Bashrc

After adding the line all you have to do is to end your current bash session and start the new one. You will see the screenfetch logo in the new session along with some basic system information.

Screen Fetch Bash

Installing and configuring zsh and oh-my-zsh

First thing before you start customizing zsh is to of course install it with the following command.

sudo apt install zsh -y
    

Once installed, you are still using bash. In order to switch to zsh you need to run the following command.

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
    

Once command is executed your current session will switch to zsh. However, you will not notice any significant visual changes. In order to make zsh more appealing you need to install additional theme for zsh.

In order to do so you need to clone the following github repository 

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k
    

Once the repository is cloned you need to update zsh profile. As for screenfect config for bash previously, I use nano

nano ~/.zshrc
    

You need to replace the ZSH_THEME settings as following

Apply Zsh Theme

Just to be on the safe side and be able to easily go back to previous theme I commented out old theme and added new line right below the commented one ZSH_THEME="powerlevel10k/powerlevel10k"

In order to apply new theme, you need to start new sessions. Simply run exit or close the current tab in Windows Terminal. 

Before you start your new zsh session, we need to update the font for Ubuntu 20 profile to use different font in order to be able to display characters zsh theme uses. You can find fonts on nerdfonts.com. Once downloaded, unzip the package and install fonts you downloaded.

Alternatively you can use fontforge and python script from the nerdfonts.com to patch your favorite font, but you can also find tons of already patched fonts directly in the github repository https://github.com/ryanoasis/nerd-fonts/tree/master/patched-fonts

After fonts are installed, you need to reference one of the fonts in the Windows Terminal profile. Make sure you set the correct fotn name. Double click on the patched font file (usually has Complete in the name) and get the name from the dialog window

Font Name

You can install the font from the same Windows dialog.

    {
      "guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",
      "hidden": false,
      "name": "Ubuntu-20.04",
      "source": "Windows.Terminal.Wsl",
      "fontFace": "DroidSansMono Nerd Font"
    }
    

You are ready now to configure zsh theme by starting new session. The configuration wizard will start and guide you through theme configuration. If you find your configuration not exactly as you imagine it, you can always go back and re-configure by initialing the wizard by running the following command

p10k configure
    

Since we switched to zsh profile, screenfetch will not be in place, so you need to update zsh profile

nano ~/.zshrc 
    

Add screenfetch to the end of the file just like previously in bsh profile config. Next time you start new zsh session you will have both screenfetch and customized szh theme in place

Wsl Ubuntu Zsh

Switching from zsh to bash and back

If you do not like your new environment you can always switch back to bash and from bash bash to zsh. To check your current setting you can run

echo $SHELL
    

To switch back to bash from zsh, you just need to run

chsh -s /bin/bash
    

and back to zsh

chsh -s /bin/zsh
    

References

Disclaimer

Purpose of the code contained in snippets or available for download in this article is solely for learning and demo purposes. Author will not be held responsible for any failure or damages caused due to any other usage.


About the author

DEJAN STOJANOVIC

Dejan is a passionate Software Architect/Developer. He is highly experienced in .NET programming platform including ASP.NET MVC and WebApi. He likes working on new technologies and exciting challenging projects

CONNECT WITH DEJAN  Loginlinkedin Logintwitter Logingoogleplus Logingoogleplus

.NET

read more

JavaScript

read more

SQL/T-SQL

read more

Umbraco CMS

read more

Comments for this article