CODEX

How to: Pimp my Powerline in PowerShell

Want to make the basic PowerShell window visually appealing? Then this guide is for you.

Jong-Chan Chung
CodeX
Published in
5 min readMar 25, 2021

--

Powershell window after applying oh-my-posh theme “slim”
PowerShell Powerline after applying oh-my-posh theme “slim”

Note: I assume that you are on a Windows 10 and I suggest you go ahead and install the latest versions of the Windows Terminal (preferably from the Microsoft Store), PowerShell7 (scroll down the GitHub webpage to “Get PowerShell”), and the version control system Git if you haven’t already done so. They just make life easier. We will make use of Oh-my-Posh, a “prompt theme engine for any shell”. If you run into problems, there is a troubleshooting section at the very end of this article.

First, let’s open up Windows Terminal by clicking the Windows Terminal button on the taskbar.

Click on the Windows Terminal button next to the red arrow

You should see something similar to below. Tap the down arrow on the upper window bar and select PowerShell if by any chance your current shell is not PowerShell.

A boring PowerShell interface

Installing a Nerd Font

As you can see, the visual appeal is not really there. It’s kind of bleak. We are going to change that. Let’s start by installing a more interesting font that allows for displaying neat symbols and is compatible with powerline glyphs. While this tutorial recommends using the Cascadia Code PL or the Cascadia Mono PL fonts, they did not render the glyphs for me. I found that the Oh-my-Posh developers designed their software to be used with nerd fonts. You are free to download and install any nerd font but I am going to stick with an elevated Cascadia Code font. If you want to follow me, grab the Cascadia Code Nerd Font provided here by downloading “CascadiaCode.Nerd.Font.Complete.ttf”. Open the file and you should see a new window pop-up:

Install ‘Cascadia Code Nerd Font Complete’

Click install. Alternatively, go to the directory where you downloaded the .ttf file, right-click on it and select “Install” or “Install for all users”.

Change the Windows Terminal Settings

Now that you have the nerd font installed, we want the PowerShell to display text using the Cascadia Code Nerd Font. The best way is to go to settings either by clicking on the down arrow on the upper window bar or by pressing [Ctrl+,] in Windows Terminal. This should open up a “settings.json” file in your default code editor. In my case, it is VS Code.

Changing the Default Font

As you can see, I have uncommented my default font “Consolas”. We are going to replace the default font with “CascadiaCode Nerd Font”. It is crucial that you omit the space between “Cascadia” and “Code” — that is no typo. When you save the file [Ctrl+S], you should see your PowerShell font change.

Install and Import Posh-Git and Oh-My-Posh

In PowerShell, execute the following two commands which will install the posh-git and the oh-my-posh modules. If you wonder what posh-git is for: “Posh-Git adds Git status information to your prompt as well as tab-completion for Git commands, parameters, remotes, and branch names” — a nice-to-have when you work with Git version control.

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

It might be that you are asked to approve the installation after you hit enter. In this case select “[Y] Yes” or “[A] Yes to All”.

Next, you need to import these modules to actually make use of them. In PowerShell, enter:

notepad $profile

which should open a file called “Microsoft.PowerShell_profile.ps1”. Create this file if it does not exist yet. Then, copy-paste the following three lines into the Notepad file like so:

Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt -Theme slim

Don’t forget to save after you make changes.

The Perfect Theme

Great! You have successfully set up oh-my-posh. However, there is a good chance that the ‘slim’ theme that I personally like most is not really your taste. Fortunately, there are many other themes to choose from. Simply enter

Get-PoshThemes

into PowerShell, to get a nice overview of the themes available. Here is the output:

Oh-My-Posh Themes Overview

Note: I have initialized a Git repository to have the powerline Git glyphs displayed as well.

To set a theme permanently, you need to call the PowerShell profile again like before with

notepad $profile

and replace the current theme, e.g.:

Set-PoshPrompt -Theme jandedobbeleer

The Final Touch (optional)

You might wonder how I have changed my local user account name from “jcchu” to “SonGoku” and my computer name toKamehameha”.

To change the user name:

  1. [Windows Key+R]
  2. Enter “netplwiz”
  3. On the new window, select the user account name to be changed
  4. Click “Properties”
  5. On the new window, enter a new user name
  6. Click “Apply”
  7. For the change to take effect, a restart is usually required

To change the computer name:

  1. [Windows Key]
  2. Start typing “About your PC” and enter
  3. On the new window, click “Rename this PC”
  4. Enter a new computer name
  5. Restart PC

Remove the PowerShell start text

You might also want to remove the PowerShell start text:

PowerShell Start Text
  1. Open Windows Terminal settings [Ctrl+,]
  2. Replace the “source” attribute with the following:
"commandline": "pwsh.exe -noLogo"
Uncommenting source and supplementing the “noLogo” argument to commandline

You are done! Enjoy the view! 😍

Extra: Troubleshooting

Enabling running scripts

You might run into an error message telling that you cannot run the .ps1 script file. One solution is to set the execution policy to “Unrestricted” or “RemoteSigned” as an administrator, like so:

Set-ExecutionPolicy Unrestricted

Shortcut problem

At some point, you might see an error that starts with “Unable to modify the shortcut”. Here, a potential solution is to go to the shortcut and give yourself full permission.

beautiful. 🙌

--

--

Jong-Chan Chung
CodeX
Writer for

Crypto and data enthusiast working in the blockchain and DeFi space. Outside of work, I enjoy walking my dog, a miniature spitz.