Skip to content

Instantly share code, notes, and snippets.

@zachrank
Created August 8, 2022 01:43
Show Gist options
  • Star 33 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save zachrank/fc71ed301e9823264ddac4fb77975735 to your computer and use it in GitHub Desktop.
Save zachrank/fc71ed301e9823264ddac4fb77975735 to your computer and use it in GitHub Desktop.
WSL 2 + Windows Terminal + Oh My Zsh + Powerlevel10k

WSL 2 + Windows Terminal + Oh My Zsh + Powerlevel10k

wsl2-zsh-powerlevel10k

This gist takes heavy inspiration from kevin-smets / iterm2-solarized.md gist for iTerm2.

Windows Subsystem for Linux 2 (WSL 2)

The first thing that you will want to do is install WSL 2 and a Linux distro.

WSL 2 is an overhauled version of the original Windows Subsystem for Linux (WSL 1) that provides a real Linux kernel under the hood. More details on the differences can be found here.

For me, one of the biggest benefits is being able to run Docker containers from within WSL. This makes developing software on Windows that is intended to run on Linux much more attractive and resolves a lot of headaches that I had with WSL 1.

Full instructions for installing WSL 2 and choosing a Linux distro can be found here.

Upgrading a Linux distro from WSL 1 to WSL 2

If you had previously installed a Linux distro with WSL 1 then you will need to manually switch it over to WSL 2. Follow the guide here for instructions on checking if your Linux distro is using WSL 1 or 2 and instructions on switching it over to WSL 2 if needed.

Windows Terminal

Now that WSL 2 is installed, you will next want to install Windows Terminal. Microsoft has documententation containing installation instructions and some basic setup tasks.

Once set up, you can open a shell into your chosen Linux distro from Windows terminal.

Color schemes

You can update or add new color schemes to Windows terminal in its settings. There are a few bundled color schemes to choose from including the popular Solarized Dark. You can modify existing schemes and add new schemes within the GUI or you can open up settings.json and add your open color schemes under the schemes property.

More themes are available at Windows Terminal Themes. You can contribute new themes by opening a PR to their git repo or by contributing to iTerm2 Color Schemes which they derive/mirror most of their themes from.

You can set the color sheme for your Linux distro's profile from within the Appearance settings or within settings.json under the profiles/list/[]/colorSheme property.

I chose to install the color scheme Ubuntu from Windows Terminal Themes in my screenshots.

Solarized Dark contrast patch

If you're using Solarized Dark then you will probably want to install the patched version of it that increases contrast between the background and the foreground text (especially for zsh-autosuggestions which we will install later).

Original

solarized-dark-original

Patched

solarized-dark-patched

Oh My Zsh

Oh My Zsh is a framework for Zsh that allows us to install fancy plugins and themes.

From this point onward, I will be assuming that you are using Ubuntu for your Linux distro. Other distros may have slightly different commands / installation instructions for any programs that we install within WSL 2 later on.

Installing Zsh

If you haven't already, update your distro's package manager's list of packages.

sudo apt update

Install Zsh using your package manager.

sudo apt install zsh

Run Zsh for the first time in order to create the its startup files (ex: .zshrc, etc.).

exec zsh

Finally, make Zsh your default shell.

chsh -s $(which zsh)

Installing Oh My Zsh

Full instructions can be found here.

First, make sure that your distro has git and also curl or wget installed (I will be using curl in my examples). If you don't have your preferred text editor like vim or emacs or nano installed then please also take care of that (I will be using vim in my examples). You can install them using your package manager.

sudo apt install <program name(s)>

Next, download and run the Oh My Zsh installation script. This will update your ~/.zshrc file and change the style of your prompt.

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

Installing zsh-autosuggestions

This is a plugin for Oh My Zsh that will show autocomplete options for commands as you type them.

Documentation can be found here

To install it, first clone its git repo into the Oh My Zsh custom plugins directory

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

Then add zsh-autosuggestions to the plugins setting in ~/.zshrc

vim ~/.zshrc

Installing zsh-syntax-highlighting

This is a plugin for Oh My Zsh that provides syntax highlighting for commands as they are being typed.

Documentation can be found here

To install it, first cloen its git repo into the Oh My Zsh custom plugin directory

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

Then add zsh-syntax-highlighting to the plugins setting in ~/.zshrc

vim ~/.zshrc

Powerlevel10k

Powerlevel10k is a theme for Zsh that will make our shell look fancy and display extra information in the prompt like the currently checked out git branch and a timestamp. We will be installing it as a theme for Zsh using Oh My Zsh.

Full installation instructions can be found here.

Installing Fonts

Prior to installing Powerlevel10k we will want to install a font to Windows that provides some extra glyphs and symbols for Powerlevel10k to display. The setup process for Powerlevel10k is reliant on the installed font for your terminal.

Powerlevel10k provides a font called "Meslo Nerd Font" that it recommends for full compatibility. Installation instructions can be found here.

Powerlevel10k works best with Nerd Fonts as they provide all the glyphs/symbols that are needed for all of Powerlevel10ks style options. Other fonts, like those bundled with Windows, can be used as well but may not have all of Powerlevel10k's features unlocked. More info can be found here.

Once you download a font, you will want to install it to Windows (not your Linux distro). You can then set the font face for your Linux distro's profile from within the Appearance settings of Windows Terminal or within settings.json under the profiles/list/[]/font/face property.

I chose to install the font UbuntuMono from Nerd Fonts so that is what you will see in my screenshots.

Installing Powerlevel10k

Clone the Powerlevel0k git repo.

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

Use your text editor to set the value of ZSH_THEME to "powerlevel10k/powerlevel10k" in ~/.zshrc.

vim ~/.zshrc

Configure Powerlevel10k for the first time by running Zsh again. The options that you are presented will be based upon what font you have installed and the glyphs/symbols that it provides.

exec zsh

If you need to re-run or reconfigure Powerlevel10k you can do so by running the following.

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