My PowerShell profile

Your PowerShell profile gives you the power to customize the console at run time. This article explores my customization that make my PowerShell sessions feel like home.

Requirements

There are four requirements to make my setup work:

  • [module] PSReadline – is included by default in PowerShell 5.0+.
  • [module] AdvancedHistory – this is a module I wrote that adds keyboard navigable history to the console.
  • [module] Posh-Git – adds the ability to show Git status as part of your prompt and adds tab-complete to Git commands and parameters. (requires some tweaking, see below)
  • [font] DejaVu Sans Mono – any Powerline font will work but I personally use DejaVu Sans Mono.

My Colour Scheme

Unfortunately setting the colours in PowerShell is tedious and it’s not easy to export or share the settings. To set these colours you will need to open PowerShell, click the logo in the top right corner of the window, select Properties, and then Colors. Click each colour going from left-to-right and use these values:

  • Black: 35, 51, 68
  • DarkBlue: 50, 117, 255
  • DarkGreen: 68, 190, 136
  • DarkCyan: 20, 133, 156
  • DarkRed: 170, 59, 43
  • DarkMagenta: 136, 68, 190
  • DarkYellow: 185, 191, 81
  • Gray: 232, 238, 251
  • DarkGray: 139, 142, 150
  • Blue: 102, 151, 255
  • Green: 85, 238, 170
  • Cyan: 29, 191, 224
  • Red: 213, 74, 54
  • Magenta: 170, 85, 238
  • Yellow: 232, 239, 102
  • White: 255, 255, 255 (default)

Before clicking “OK” make sure you have the “Screen Background” radio selected and click the furthest colour on the left (“Black.”)

On Windows the colour settings are stored in the actual shortcut used to launch the current session and can be copied between locations.

  • Start menu shortcuts: AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell
  • Taskbar shortcuts: AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar

My Profile

Editing the Profile

There are multiple profiles for PowerShell and PowerShell ISE but the one we’re concerned with is the PowerShell console profile specific to the current user. The location of the user profile is assigned to the variable $PROFILE and can be created and opened from the command-line:

  • If the Test-Path command comes back True you already have a profile and can skip the New-Item command.
  • You can substitute “code” with “ise” or any editor of your choice.

My Profile

Before starting:make sure to set the font within PowerShell to DejaVu or whichever Powerline font you selected.

Tweaking Posh-Git

Finally, in order to make Posh-Git fit into the prompt naturally we need to make changes to GitPrompt.ps1 in the Posh-Git installation directory ( C:\Program Files\WindowsPowerShell\Modules\posh-git\0.7.3  if installed for all user on Windows.)

Replace lines 5-86 with this: