Recently I wanted to spice up a little my command line in Windows. I didn’t want to install any fancy terminals, mess with my default settings, and so on. I use PowerShell from many different apps, some of which have it integrated so juggling all of that by moving from PowerShell 5 to PowerShell 7 is just not worth it. PowerShell is the default terminal in Windows and can not be uninstalled. PowerShell 7 is an updated version and has many creature comforts added to it but is not an update to PowerShell 5 but runs alongside it, hence the issue with changing a lot of configurations to make that default.
While there is ohMyPosh that provides themes for terminals I wanted to do it myself and maybe learn something about PowerShell scripting along the way.
I don’t want to touch my setup just so I could have some colors of some fancy terminal. But, after some snooping, I realized that to get the desired outlook I needed to change the font. PowerShell default font is Consolas but it’s missing some symbols I wanted so I downloaded Consolas NF from Alex on Git Hub. It is Consolas font with the addition of Nerd Fonts which adds some 9,222 additional characters, and icons to the font repository. Once the font is downloaded double-click it and when the preview window shows up click Install. We will need to change the font wherever the terminal is used but it’s a sacrifice I was willing to make for some bling.
You can view them by using the Character Map app that comes with every Windows.
The alternative was to find a way to spice up PowerShell 5 a little bit. So I thought that I could add some flair to the startup script that I wrote to identify from where, and what process, the PowerShell was started, I removed that part as it was not needed anymore. I figured I could also add a startup banner to it.
So, to create a startup script for PowerShell 5 create a Microsoft.PowerShell_profile.ps1 in <user>\Documents\WindowsPowerShell\ folder
The ASCII banner was made using Text to ASCII Generator from patorjk.com.
The above prompt is made using the script below.
Write-Host " "
Write-Host " __ __ _ _____ " -ForegroundColor Blue
Write-Host " / / /\ \ \__ _ _ __ _ __ ___ __| |___ / " -ForegroundColor Blue
Write-Host " \ \/ \/ / _` | '__| '_ \ / _ \/ _` | |_ \ " -ForegroundColor Blue
Write-Host " \ /\ / (_| | | | |_) | __/ (_| |___) | " -ForegroundColor Blue
Write-Host " \/ \/ \__,_|_| | .__/ \___|\__,_|____/ " -ForegroundColor Blue
Write-Host " |_| " -ForegroundColor Blue
function prompt {
# Get the free space for the C drive in GB
$freeSpace = '{0:N2} GB' -f ((Get-PSDrive C -PSProvider 'FileSystem').Free / 1GB)
# Get the current time
$currentTime = Get-Date -Format "HH:mm:ss"
# Get the current directory
$currentDir = Get-Location
$folders = $currentDir.Path.Split('\')
# Define a list of colors for the folders
$colors = @('Red', 'Green', 'Blue', 'Cyan', 'Magenta', 'Yellow', 'DarkGray')
# Write the free space information before the folders
Write-Host ([char]::ConvertFromUtf32(0xE240)) $freeSpace " " -NoNewline -ForegroundColor Green
Write-Host ([char]::ConvertFromUtf32(0xE0B6)) -NoNewline -ForegroundColor $colors[0]
Write-Host ([char]::ConvertFromUtf32(0xE5FE)) " " -NoNewline -BackgroundColor $colors[0]
# Iterate through each folder in the path
for ($i = 0; $i -lt $folders.Length; $i++) {
# Select a color from the array for the current folder
$currentColor = $colors[$i % $colors.Length]
# Write the current folder with its color
Write-Host $folders[$i] -NoNewline -ForegroundColor White -BackgroundColor $currentColor
# Determine the color for the next folder, if there is one
if ($i -lt $folders.Length - 1) {
$nextColor = $colors[($i + 1) % $colors.Length]
# Write the powerline symbol with the current background and next background colors
Write-Host ([char]::ConvertFromUtf32(0xE0B0)) -NoNewline -ForegroundColor $currentColor -BackgroundColor $nextColor
}
}
# After the last folder, set the powerline symbol with the last color as the foreground and no background
$lastColor = $colors[($folders.Length - 1) % $colors.Length]
Write-Host ([char]::ConvertFromUtf32(0xE0B4)) -NoNewline -ForegroundColor $lastColor
Write-Host " "([char]::ConvertFromUtf32(0xF43A)) "$currentTime" -NoNewline -ForegroundColor Green
# Add a customized prompt symbol and reset colors
Write-Host " " -ForegroundColor White -BackgroundColor Black
Write-Host ([char]::ConvertFromUtf32(0xFC96)) -NoNewline -ForegroundColor $lastColor
# Return an empty string for the prompt
return " "
}
If you don’t see the icons, check if Consolas NF is set as your terminal font.
Hope you found this interesting as I did. I could have installed additional software for something that can be done … the hard way. This way, at least I learned a little about PowerShell script programming.
PS> If you create some customized PowerShell prompts I would really like to see what you came up with.