Powerline for Windows Terminal: Adding final touches

There’s already a complete guide on getting the Poweline setup on Windows Terminal. However, for complete personalization, there are a few more steps you can take. This includes installing Powershell Core, changing the terminal color scheme and perhaps tweak the Poweline theme itself. Here’s my guide to the last stretch of personalization.

Install Powershell Core and make it the default shell

You can find the latest Powershell Core on their GitHub Releases page. Installation is straightforward of course. But, it only gets listed as an available shell in the Terminal menu and there’s no option in the UI to make it the default. Instead, you need to configure it in settings.json. Click on the Settings options in the menu to open it.

Once there, locate the entry for Powershell Core under profiles: lists. Copy the guid.

Replace the value of the defaultProfile with the copied guid.

Make the Terminal always start in a specific folder

By default the Terminal starts in the home directory for your profile. You may want it to start in your projects folder instead. This is easy to achieve. Go to the defaults inside the profiles section of the settings.json. You already used this section to set the fontFace while setting up Powerline. Add startingDirectory property with the absolute path to your desired folder.

Use a custom Windows Terminal color scheme

The default Terminal color scheme (Tango Dark) was a little too black for me. I picked Cobalt2 from a list of custom schemes I found. Find the schemes property on the settings.json. By default this would be an empty array. Paste the json for the custom color scheme to this array.

Now add a colorScheme property with the name of the custom color scheme you pasted, under the profiles: defaults section.

Tweak the Powerline

Remove the username@Computer from the start of the Powerline

If you are using Paradox or Agnoster themes, they’ll print your username and machine name at the beginning of the prompt. Which would be bit of a waste of space in most cases. Turns out this is easy to fix. Open the PowerShell profile for edit in VS Code by entering the following in the PS prompt:

> code $PROFILE

Add the following to the top of the file (other lines would already be there from you Powerline setup).

$global:DefaultUser = [System.Environment]::UserName
Import-Module posh-git
Import-Module oh-my-posh

Move the timestamp to the front of the Powerline

Now, lets put the space gained to good use. The Paradox theme already prints the timestamp at the end of the line. However, I find it more useful to have it in the beginning.

Here’s the easy way to do this:

In Powershell, enter $ThemeSettings. And you’ll see something similar to the following.

I’ve highlighted two properties that we are going to need.

First enter the following at the prompt to open the Paradox theme in VS Code

> code $ThemeSettings.CurrentThemeLocation

Copy the entire contents of the file. Enter the following in the prompt next:

> code $ThemeSettings.MyThemesLocation/MyParadox.psm1

Past what you copied before in the file and save. You now have a clone of the Paradox theme called MyParadox.

Now, you can modify the new theme to your liking. I’ve posted mine which I call the TimeParadox, at the end of this post. You can do a diff on it to see the changes I’ve made.

Show Powerline in VS Code

When you customize the Powershell, it affects everywhere a PS terminal is used. An example is the Integrated Terminal on VS Code. However, VS Code will automatically pick up the Powerline font making it look really icky.

Here’s how you fix this:

Press Ctrl+Shift+P and open the Preferences: Settings (UI).

Switch VS Code to Powershell Core

Type shell to find the Automated Shell: Windows section. Click Edit in settings.json.

Find and update the following property with the path to PS Core you installed.

"terminal.integrated.automationShell.windows": "C:\\Program Files\\PowerShell\\7\\pwsh.exe"

While you are here, update the Terminal font as well.

"terminal.integrated.fontFamily": "\"Cascadia Code PL\"",

Now restart VS Code. You may also need to select PS Core as the default shell when it restarts.

TimeParadox Powerline Theme

#requires -Version 2 -Modules posh-git
function Write-Theme {
param(
[bool]
$lastCommandFailed,
[string]
$with
)
$lastColor = $sl.Colors.PromptBackgroundColor
$prompt = Write-Prompt Object $sl.PromptSymbols.StartSymbol ForegroundColor $sl.Colors.PromptForegroundColor BackgroundColor $sl.Colors.SessionInfoBackgroundColor
#check the last command state and indicate if failed
If ($lastCommandFailed) {
$prompt += Write-Prompt Object "$($sl.PromptSymbols.FailedCommandSymbol) " ForegroundColor $sl.Colors.CommandFailedIconForegroundColor BackgroundColor $sl.Colors.SessionInfoBackgroundColor
}
#check for elevated prompt
If (Test-Administrator) {
$prompt += Write-Prompt Object "$($sl.PromptSymbols.ElevatedSymbol) " ForegroundColor $sl.Colors.AdminIconForegroundColor BackgroundColor $sl.Colors.SessionInfoBackgroundColor
}
$user = $sl.CurrentUser
$computer = $sl.CurrentHostname
$path = Get-FullPath dir $pwd
if (Test-NotDefaultUser($user)) {
$prompt += Write-Prompt Object "$user@$computer " ForegroundColor $sl.Colors.SessionInfoForegroundColor BackgroundColor $sl.Colors.SessionInfoBackgroundColor
}
else {
$timeStamp = Get-Date UFormat "{0:hh:mm:tt}"
$prompt = Write-Prompt Object "$timeStamp" ForegroundColor $sl.Colors.SessionInfoForegroundColor BackgroundColor $sl.Colors.SessionInfoBackgroundColor
}
if (Test-VirtualEnv) {
$prompt += Write-Prompt Object "$($sl.PromptSymbols.SegmentForwardSymbol) " ForegroundColor $sl.Colors.SessionInfoBackgroundColor BackgroundColor $sl.Colors.VirtualEnvBackgroundColor
$prompt += Write-Prompt Object "$($sl.PromptSymbols.VirtualEnvSymbol) $(Get-VirtualEnvName) " ForegroundColor $sl.Colors.VirtualEnvForegroundColor BackgroundColor $sl.Colors.VirtualEnvBackgroundColor
$prompt += Write-Prompt Object "$($sl.PromptSymbols.SegmentForwardSymbol) " ForegroundColor $sl.Colors.VirtualEnvBackgroundColor BackgroundColor $sl.Colors.PromptBackgroundColor
}
else {
$prompt += Write-Prompt Object "$($sl.PromptSymbols.SegmentForwardSymbol) " ForegroundColor $sl.Colors.SessionInfoBackgroundColor BackgroundColor $sl.Colors.PromptBackgroundColor
}
# Writes the drive portion
$prompt += Write-Prompt Object "$path " ForegroundColor $sl.Colors.PromptForegroundColor BackgroundColor $sl.Colors.PromptBackgroundColor
$status = Get-VCSStatus
if ($status) {
$themeInfo = Get-VcsInfo status ($status)
$lastColor = $themeInfo.BackgroundColor
$prompt += Write-Prompt Object $($sl.PromptSymbols.SegmentForwardSymbol) ForegroundColor $sl.Colors.PromptBackgroundColor BackgroundColor $lastColor
$prompt += Write-Prompt Object " $($themeInfo.VcInfo) " BackgroundColor $lastColor ForegroundColor $sl.Colors.GitForegroundColor
}
# Writes the postfix to the prompt
$prompt += Write-Prompt Object $sl.PromptSymbols.SegmentForwardSymbol ForegroundColor $lastColor
$prompt += Set-Newline
if ($with) {
$prompt += Write-Prompt Object "$($with.ToUpper()) " BackgroundColor $sl.Colors.WithBackgroundColor ForegroundColor $sl.Colors.WithForegroundColor
}
$prompt += Write-Prompt Object ($sl.PromptSymbols.PromptIndicator) ForegroundColor $sl.Colors.PromptSymbolColor
$prompt += ' '
$prompt
}
$sl = $global:ThemeSettings #local settings
$sl.PromptSymbols.StartSymbol = ''
$sl.PromptSymbols.PromptIndicator = [char]::ConvertFromUtf32(0x276F)
$sl.PromptSymbols.SegmentForwardSymbol = [char]::ConvertFromUtf32(0xE0B0)
$sl.Colors.PromptForegroundColor = [ConsoleColor]::White
$sl.Colors.PromptSymbolColor = [ConsoleColor]::White
$sl.Colors.PromptHighlightColor = [ConsoleColor]::DarkBlue
$sl.Colors.GitForegroundColor = [ConsoleColor]::Black
$sl.Colors.WithForegroundColor = [ConsoleColor]::DarkRed
$sl.Colors.WithBackgroundColor = [ConsoleColor]::Magenta
$sl.Colors.VirtualEnvBackgroundColor = [System.ConsoleColor]::Red
$sl.Colors.VirtualEnvForegroundColor = [System.ConsoleColor]::White
$sl.Colors.SessionInfoBackgroundColor = [ConsoleColor]::DarkCyan
view raw TimeParadox.psm1 hosted with ❤ by GitHub

Also for reference, here’s my settings.json for Powershell.

// This file was initially generated by Windows Terminal 1.3.2651.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
// You can add more global application settings here.
// To learn more about global settings, visit https://aka.ms/terminal-global-settings
// If enabled, selections are automatically copied to your clipboard.
"copyOnSelect": false,
// If enabled, formatted data is also copied to your clipboard
"copyFormatting": false,
// A profile specifies a command to execute paired with information about how it should look and feel.
// Each one of them will appear in the 'New Tab' dropdown,
// and can be invoked from the commandline with `wt.exe -p xxx`
// To learn more about profiles, visit https://aka.ms/terminal-profile-settings
"profiles":
{
"defaults":
{
// Put settings here that you want to apply to all profiles.
"fontFace": "Cascadia Code PL",
"startingDirectory": "C:\\Users\\Sameera\\Documents\\Dev",
// "colorScheme": "MaterialDark",
"colorScheme": "Cobalt2"
},
"list":
[
{
// Make changes here to the powershell.exe profile.
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"hidden": false
},
{
// Make changes here to the cmd.exe profile.
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "Command Prompt",
"commandline": "cmd.exe",
"hidden": false
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": false,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
},
{
"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"hidden": false,
"name": "PowerShell",
"source": "Windows.Terminal.PowershellCore"
}
]
},
// Add custom color schemes to this array.
// To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
"schemes": [{
"background": "#193549",
"black": "#000000",
"blue": "#1478DB",
"brightBlack": "#808080",
"brightBlue": "#1478DB",
"brightCyan": "#00ffff",
"brightGreen": "#33ff00",
"brightPurple": "#cc00ff",
"brightRed": "#ff0000",
"brightWhite": "#ffffff",
"brightYellow": "#ffff00",
"cyan": "#00c5c7",
"foreground": "#c7c7c7",
"green": "#3AD900",
"name": "Cobalt2",
"purple": "#ff2c70",
"red": "#ff2600",
"white": "#c7c7c7",
"yellow": "#ffc600"
}, {
"name": "MaterialDark",
"black": "#212121",
"red": "#b7141f",
"green": "#457b24",
"yellow": "#f6981e",
"blue": "#134eb2",
"purple": "#560088",
"cyan": "#0e717c",
"white": "#efefef",
"brightBlack": "#424242",
"brightRed": "#e83b3f",
"brightGreen": "#7aba3a",
"brightYellow": "#ffea2e",
"brightBlue": "#54a4f3",
"brightPurple": "#aa4dbc",
"brightCyan": "#26bbd1",
"brightWhite": "#d9d9d9",
"background": "#232322",
"foreground": "#e5e5e5"
}
],
// Add custom actions and keybindings to this array.
// To unbind a key combination from your defaults.json, set the command to "unbound".
// To learn more about actions and keybindings, visit https://aka.ms/terminal-keybindings
"actions":
[
// Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
// These two lines additionally bind them to Ctrl+C and Ctrl+V.
// To learn more about selection, visit https://aka.ms/terminal-selection
{ "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+c" },
{ "command": "paste", "keys": "ctrl+v" },
// Press Ctrl+Shift+F to open the search box
{ "command": "find", "keys": "ctrl+shift+f" },
// Press Alt+Shift+D to open a new pane.
// "split": "auto" makes this pane open in the direction that provides the most surface area.
// "splitMode": "duplicate" makes the new pane use the focused pane's profile.
// To learn more about panes, visit https://aka.ms/terminal-panes
{ "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+d" }
]
}
view raw settings.json hosted with ❤ by GitHub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.