How to Install Powerline in WSL2 Terminal


Let’s spice things up and get a new interface to our WSL2 terminal with Powerline.

Install Powerline fonts

First, we want to open Powershell as an administrator.

Then, we want to install run the following commands.

# Download Powerline fonts
powershell -command "& { iwr https://github.com/powerline/fonts/archive/master.zip -OutFile ~\fonts.zip }"
# Expand the downloaded repo
Expand-Archive -Path ~\fonts.zip -DestinationPath ~
# Update execution policy in order to install
Set-ExecutionPolicy Bypass
# Run the installation
~\fonts-master\install.ps1
# Restore original execution policy
Set-ExecutionPolicy Default

Configure Powerline fonts in WSL2

At this point, we have the Powerline fonts installed on our machine.

In order to use the fonts in the terminal, we’ll want to open up our terminal.

  1. Open Properties
  2. Navigate to the Font tab
  3. In the Font section, select a Powerline font (e.g. ProFont for Powerline).
  4. Select OK

Install Powerline

In our terminal, we’ll want to install Powerline.

# Add the Universe repo
sudo add-apt-repository universe
# Install Powerline
sudo apt install -y powerline

Configure Powerline in Bash

Let’s use our installation to configure Powerline in bash.

In ~/.bashrc, let’s add these lines:

# Powerline Configuration
if [ -f /usr/share/powerline/bindings/bash/powerline.sh ]; then
  powerline-daemon -q
  POWERLINE_BASH_CONTINUATION=1
  POWERLINE_BASH_SELECT=1
  source /usr/share/powerline/bindings/bash/powerline.sh
fi

In order to see the changes, we can either restart our terminal, or source the file.

source ~/.bashrc

Configure Powerline in Vim

Another useful use of Powerline is in Vim.

First, we can install the latest version of vim.

sudo apt update
sudo apt install -y vim

Then, we can add these lines in ~/.vimrc.

# Powerline Configuration
python3 from powerline.vim import setup as powerline_setup
python3 powerline_setup()
python3 del powerline_setup

set laststatus=2