windows terminal

Tweaking the PowerShell colour scheme to play nice with the new Windows Terminal

I have been using the new Windows Terminal along with PowerShell Core lately and followed the latest steps from Scott Hanselman to add some nice functionality, fonts and colours to my terminal. You can read the blog post here:

One thing I did find tricky was getting all of the text colours to play along nicely between the windows terminal theme, any custom backgrounds you may add and the default PowerShell colours.

For example when using the 'Solarized Dark' theme, you may find that the flag text color may appear invisble due to the clash with the background color. By default the following command would render with the flag pretty much invisible

dotnet new console -o AwesomeApp

You can check what your current colour scheme is using the following command

Get-PSReadlineOption | Select *color

You can see from the screenshot above however, that two tokens appear completley invisible due to the color clash, TypeColor and VariableColor (I had to actually copy and paste the empty lines to see the text)

Ok, so to set these two tokens to a colour that will work with this colour scheme, we can set the colour in the PowerShell profile.

Open your profile from PowerShell using the following command

notepad $PROFILE

You can then add the following, setting the relevant token names to the desired colour, we will set both to Magenta in this example. Note this is for PowerShell Core and PSReadline v2.0. Depending on your version the exact format of the command below may differ slightly.

Set-PSReadLineOption -Colors @{
   "Type" = [ConsoleColor]::Magenta;
   "Variable" = [ConsoleColor]::Magenta

Now if you save your profile and open a new terminal window or tab, then run the command again to show your color scheme, you should see your changes in effect.

What you may have noticed, depending on your PowerShell version, is that the incorrect tokens were changed to Magenta. If you look above,the subsequent token for Type and Variable were set and not the tokens themselves. There is a bug somewhere, not sure if its with the latest PowerShell Core but I have been able to replicate the bug of two different machines running Windows Terminal and Powershell Core.

If you do happen to experience the weird bug above, simply change the token in the PowerShell profile to the previous token and it should do the trick. Also note if a fix is pushed to resolve this bug you will need to update your profile again to use the correct token.

My final profile looks like:

Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox
Set-PSReadLineOption -Colors @{
   "Operator" = [ConsoleColor]::Magenta;
   "Parameter" = [ConsoleColor]::Magenta

You can now see that our Type and Variable tokens are now showing and when we type in the command we had issue with at the start of the post, we can now see the flag correctly

dotnet new console -o AwesomeApp

Hope this helps anyone else running into this issue!