Using Paths in Prompts

by Oct 27, 2015

The default PowerShell prompt displays the current location. When you are deep inside nested folders, this steals room for your actual input, and you may have to scroll a lot.

There are plenty of ways how to deal with it. Here are two alternate prompt functions to work around this.

The first one keeps the current path in the prompt, but the actual input occurs one line below, so your input is always visible:

function prompt
{
  Write-Host("PS: $pwd>")
}

The alternative way is displaying the current location in the window titlebar:

function prompt
{
  $host.UI.RawUI.WindowTitle = Get-Location
  'PS> '
}

If you like one of these functions, place them into your autostart profile script (which may not yet exist). The path can be found in $profile.

Twitter This Tip! ReTweet this Tip!