Learn how to customize your PowerShell console to display meaningful metadata in your Windows command shell with Powerline.

I'll never forget attending a technical conference several years ago, and seeing the presenter's command shell look like this on the overhead screen:

Powerline on Linux

Powerline on Linux

"What in the world is THAT?!" I wondered. "If only I could do something like that in PowerShell…"

I have good news for you, gentle reader: Today, you'll learn precisely how to configure your Windows command shell to display. Read on!

What is Powerline? ^

Powerline is a status line plug-in for the Linux VI iMproved (Vim) text editor. Specifically, Powerline for Linux is a Python application that enables you to format your command prompt with a combination of colorized text and symbols ("glyphs") to make it easier for you to see at a glance:

  • Current user
  • Computer host name
  • Present working
  • Git repository status
  • Session time, system time, etc.
  • Any other metadata you're interested in viewing

The good news for us is that kind fellow community members have ported Powerline's core functionality to Windows.

Note that you'll need to think ahead and install Powerline-compatible fonts so that your customized command prompt renders correctly. Otherwise, your command prompt will be filled with "sdf" Unicode placeholder characters—not a good look!

We'll get back to the font issue momentarily. First, let's set up Powerline for our PowerShell environment in Windows. This is what my PowerShell console looks like prior to Powerline:

PowerShell console pre Powerline

PowerShell console pre Powerline

Set up Powerline ^

I assume Git integration is a big reason why you want Powerline. Thus, as a reminder, make sure you've installed the Git client on your Windows workstation.

I also assume you're running PowerShell 7; if not, why not?! Anyhow, you'll need the PSReadline module, so get that installed as well:

Install-Module -Name PSReadLine -Scope CurrentUser -Force -SkipPublisherCheck

PSReadline improves the command line editing experience in the PowerShell console. The two other modules we need to install Powerline are posh-git and oh-my-posh:

Install-Module -Name posh-git -Scope CurrentUser
Install-Module -Name oh-my-posh -Scope CurrentUser

The posh-git module gives us tab completion for Git commands as well as Git repository status information. The oh-my-posh module supports PowerShell prompt theming.

Now, about fonts. As I said earlier, most fonts don't contain the glyphs Powerline requires to display stuff like the GitHub icon and so forth. Microsoft includes the Cascadia Code PL (with "PL" standing for "Powerline") in its free font pack, so this font might be a good starting point for you.

In the community, you'll also find several community members who release "hacked" font versions that include Powerline glyphs. For example, I'm in love with Caskaydia Cove Nerd Font, which I found at the Nerd Fonts archive. Go there, have fun trying out some patched fonts, and install any you love so that they're available to Powerline!

In the next image, you can see me using good ol' Windows Explorer to install a patched Powerline font. Extract the fonts, right-click the ones in question, and then select either Install or Install for all users from the shortcut menu. Done and done.

Installing a Powerline font on Windows 10

Installing a Powerline font on Windows 10

Configure the environment ^

Open your PowerShell profile (say, in Visual Studio Code):

code $profile

Add the following lines to ensure Powerline is activated every time you launch PowerShell:

$env:POSH_GIT_ENABLED=$true
Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt -Theme paradox

The first line, in which we add an environment variable to our PowerShell session, is required to enable posh-git to perform Git command autocompletion. The second and third lines ensure that the required modules are loaded into the runspace. The final line sets the desired Powerline theme with oh-my-posh's Set-PoshPrompt function.

"What other themes are available?" you ask. I have you covered. Run Get-PoshThemes and spend some time poring over the colorized Powerline goodness. Then edit the Set-PoshPrompt statement to your desired theme.

Browsing oh my posh themes without a Powerline font installed

Browsing oh my posh themes without a Powerline font installed

You'll notice all the Unicode substitution characters in the previous screenshot. Looks bad, doesn't it? Well, we need to configure our client application to use a Powerline-compatible font.

Here are some quick instructions for getting to the font controls of some favorite Windows PowerShell console applications:

PowerShell console

  1. Open the control menu in the upper left corner of the window and select Properties.
  2. Navigate to the Font tab, make changes, and then click OK to commit.

Windows Terminal

  1. Open the Settings menu and browse to the appropriate profile.
  2. Navigate to the Appearance tab.
  3. Open the Font face list, make your change, and then click Save to commit.

Visual Studio code

  1. Click View > Command Palette, type settings, and choose Open Settings (JSON).
  2. Set the terminal.integrated.fontFamily and terminal.integrated.fontSize properties to the required values.

Check out the following screenshot, which shows my Get-PoshThemes output after I've completed my configuration:

Browsing oh my posh themes with a Powerline font loaded

Browsing oh my posh themes with a Powerline font loaded

If you want to format your terminal to show file and folder icons, perform the following actions to incorporate the Terminal-Icons module into your Powerline setup:

# Install the Terminal-Icons module
Install-Module -Name Terminal-Icons -Repository PSGallery
# Add the module import to your PowerShell profile
Import-Module -Name Terminal-Icons

I'll finish by showing you what my finished console looks like. Dramatically different, eh?

Subscribe to 4sysops newsletter!

My Powerline PowerShell console

My Powerline PowerShell console

Wrapping up ^

Now that I'm using Powerline, I can't imagine not using it whenever I'm at a PowerShell console prompt. You're not limited to PowerShell either. For instance, learn how to enable Powerline in Windows Subsystem for Linux version 2 (WSL2) and the macOS bash prompt.

+5
avataravatar
1 Comment
  1. Marc 1 month ago

    Just an FYI as it wasn't mentioned in the article, in order to use Terminal-Icons, you need to be using the patched Nerd Fonts (took me some troubleshooting to figure that out).

    +1

Leave a reply

Please enclose code in pre tags

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2021

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account