5 minutes
PowerShell Prompt: Colors and Icons
Introduction
If you have followed along with me before, chances are you know I like color. Color helps me zoom in on the information I want faster. Color can help me know if I have the right number of curly braces. Modern browsers and word processors show a red squiggly line when you misspell a word. Your eye is drawn to that bit of color that is different than the rest of the page. Keep reading and I’ll show you how to add some spice to your PowerShell experience.
Defaults
On first login to a Windows machine, your PowerShell console is going to be plain. You’re going to see the typical white text on a blue background. If you or your organization have installed PowerShell 7, you’ll see a black screen with white text.
Opening up the properties and looking under the color tab, you can see a row of sixteen colors as shown below.
These are the values the console uses for displaying colors by name.
If you run Write-Host "Test" -ForegroundColor Red
, the console will use the this value to display the text in red.
The same goes for the standard ANSI colors. The names don’t match up quite right. Here’s a table with standard names for both.
Console Color Name | ANSI Color Name | Console Color Name | ANSI Color Name |
---|---|---|---|
White | Bright White | DarkBlue | Blue |
Gray | White | DarkGreen | Green |
Blue | Bright Blue | DarkCyan | Cyan |
Green | Bright Green | DarkRed | Red |
Cyan | Bright Cyan | DarkMagenta | Magenta |
Red | Bright Red | DarkYellow | Yellow |
Magenta | Bright Magenta | DarkGray | Bright Black |
Yellow | Bright Yellow | Black | Black |
Back before I got much into customizing my prompt, I still went in and changed the background to black and changed the value of black from 12,12,12 to 0,0,0. Something to note here. The sixteen color choices are tied to the four radio buttons above them for “Screen Text”,“Screen Background”,“Popup Text” and “Popup Background”.
To change a color value you’ll need to select that color, change it and then pick the color for that radio button. For example if I have “Screen Background” selected and it’s set to black, I can click on green to change the values for green, but I need to go back and select black again before clicking ok so my background doesn’t change to green.
Colors
So by now you’ve noticed that you can change colors around but it’s not very convenient. You can play around with the color boxes, or if you want to give yourself a headache you can edit the values in the registry stored in HKCU:\Console.
ColorTool
You’re not alone in wanting color and to avoid the pain. Microsoft released a program appropriately named ColorTool as part of the Windows Terminal project on GitHub. This tool allows you to quickly change between color schemes.
Console Color Schemes
ColorTool comes with a handful of color schemes so head over to https://iterm2colorschemes.com/ and browse through over 250 color schemes. One of the things I’ve run into when messing with color palettes, is either the parameter names or values will be too dark to see. I then have to figure out which color is being used there and adjust it to something I can see better.
Another good resource mentioned in the ColorTool README, is https://terminal.sexy. Here you can visually adjust colors to see what works.
Windows Terminal
If you are using Windows Terminal you get a plain black screen. With Windows Terminal, you are already set up for using color schemes. There are a few to pick from with a new install.
Windows Terminal Color Schemes
Adjusting the colors for a theme is much nicer in Windows Terminal. The colors aren’t tied to the four function colors. Clicking on a color brings up a nice color picker.
If you want to add a color scheme, it gets a little less easy, Go to https://windowsterminalthemes.dev/ and browse for a theme that you like. Next click on the “Get theme” button. This copies the JSON to your clipboard. Now in the Window Terminal settings Color schemes tab click on the “Open JSON file” button in the lower left corner.
Once in your JSON editor of choice, scroll down to the “schemas” section. Paste your clipboard contents between the left square bracket and the left curly brace.
Scroll down to the end of what you just added and add a comma after your right curly brace.
Mac and Linux
With PowerShell on Linux or Mac, your experience depends on your terminal of choice. For MacOS I recommend iTerm2. Almost all of my Linux interaction is through ssh, so I don’t have a desktop recommendation.
Nerd Font
Nerd Fonts is a collection of fonts that have incorporated tons of extra glyphs from popular ‘iconic fonts’ such as Font Awesome, Devicons, Octicons, and others. Download the style of font you want and install it. This requires administrator access in Windows. For console work I would pick one of the monospace fonts. I made my choice based on how O,0,g,G,q & 1 looked. I like being able to tell the difference between a ‘one’ and a lowercase L or a zero and capital O.
I’ll let you figure out how to change the font for your environment. I’ve used Nerd Fonts in VSCode, Windows Terminal, Windows PowerShell, Windows PowerShell ISE and PowerShell 7 (on Windows and Mac).
Browsing the “cheat sheet” on Nerd Fonts website you can find the icon you want and grab the hex code in the bottom right corner.
[char]0xf5ea
will display the icon.
I like to put the icons I want in a PSCustomObject to easily reference
$nf=[PSCustomObject]@{
# nerdfont icons
cake=[char]0xf5ea
dollar=[char]0xf155
bang=[char]0xf12a
mail=[char]0xf003
}
Terminal Icons
Once you have picked out your font (I went with Bitstream Vera Sans Mono), you should install the Terminal-Icons
module.
It adds icons to a ton of file types as well as colorizing to the output of Get-ChildItem.
Here’s a before and after.
You’ll need to add Import-Module -Name Terminal-Icons
to your $PROFILE
Conclusion
As you can see there a lots of ways to pretty up your PowerShell window. Play around. Experiment. Most importantly, have fun.
Be sure to check out the whole series on getting the most out of the PowerShell prompt.
- PowerShell Prompt: Colors and Icons
- PowerShell Prompt: Functionality
Thanks for reading.
-Jeff
Comments powered by Talkyard.