Powershell Core

Windows 10 replaced the Command Prompt (cmd.exe) with Windows PowerShell (powershell.exe) as the default command-line interpreter (CLI). PowerShell Core (pwsh.exe) is the successor to Windows PowerShell. Until recently, I had used the Command Prompt through the Windows Terminal with the DejaVu Sans Mono font and the Solarized Dark colour scheme. What would be required to move to PowerShell Core?

Colours

Solarized provides the accent colours yellow (mapped to the terminal colour DarkYellow), orange (Red), red (DarkRed), magenta (DarkMagenta), violet (Magenta), blue (DarkBlue), cyan (DarkCyan) and green (DarkGreen).

$Host.PrivateData specifies colours for Error, Warning, Debug, Verbose and Progress (the progress bar). For example: $Host.PrivateData.ErrorForegroundColor.

I set Error red and Warning yellow (orange seemed too close to red). I set Debug green (like the colour often used for comments) and Verbose cyan. For Progress, I referenced Solarized Light and set base00 (mapped to terminal colour Yellow) on base3 (White).

Get-PSReadLineOption returns an object that can be used to specify colours for:

  • a Comment
  • a Keyword
  • a Command and its Parameter
  • a Member (property or method) of an object
  • an Operator
  • a DefaultToken
  • a Type
  • a Number (integer or real)
  • a String (delimited by single or double quotation marks)
  • a Variable
  • a ContinuationPrompt
  • Emphasis or an Error.

For example: (Get-PSReadlineOption).ErrorColor = 'DarkRed'.

PowerShell comments run from # to the end of the line or are delimited by <# #>. I set them green.

The PowerShell language has a number of keywords. I set them magenta.

I set commands and members of objects yellow and their parameters violet (a colour I had not used elsewhere).

I set operators base0 (Blue), the body text in Solarized Dark.

I set default tokens blue. Default tokens include the names of functions, braces delimiting a script block ({}), the redirection operators, the grouping operator (()), the subexpression operator ($()), the array subexpression operator (@()), the cast operator ([]), the dot sourcing operator (. ), the index operator (also []), the call operator (&), the background operator (also &), the pipeline operator (|), the member access operator (.) and the static member operator (::).

I set types to yellow, as it contrasted with the colour used for the delimiting (default) tokens [].

I set numbers base01 (mapped to terminal colour Green), the secondary content in Solarized Dark, and strings orange (as close to brown).

PowerShell variable names start with $. I set them to cyan.

I set the continuation prompt to blue, emphasis to cyan (to follow my choice for Verbose) and errors to red.

The colours are set in a PowerShell script (Set-Colours.ps1), invoked in $PROFILE:

Fonts

Windows Terminal ships with computer font Cascadia Code, a font with programming ligatures. Since version 1911.20, another version of the font, Cascadia Code PL, also includes powerline symbols (see tooling below). Font Hasklig provides powerline symbols too but its coverage of programming ligatures is more limited. I switched from DejaVu Sans Mono to Cascadia Code PL.

Tooling

The PowerShell module posh-git provides an environment for using Git on PowerShell, including Git summary status information in the PowerShell prompt.

The PowerShell module oh-my-posh builds on posh-git to provide prompt themes, making use of powerline fonts.

Aliases

PowerShell’s command names are structured (as Verb-Noun) but that structure means that frequently used commands are verbose. However, shorter aliases exist, or can be created, for such commands. For example dir (Get-Children), cd (Set-Location), copy (Copy-Item), move (Move-Item), and del or rmdir (Remove-Item).

Shortcuts

In the Command Prompt, I set environment variables to be able to change quickly to the directory for my Haskell projects or my local GitHub repositories (eg cd %Haskell%). PowerShell allowed for more powerful shortcuts. I created a module script Set-Shortcuts.psm1 that exported functions Set-Haskell and Set-GitHub: