I would like to shorten my PowerShell prompt so that it just shows the parent directory and the current directory. For example, if the pwd is
C:\\Users\\ndun
Try this (too long for a comment):
function prompt
{
$aux=$executionContext.SessionState.Path.CurrentFileSystemLocation.Path -Split '\\|\/'
if ( $aux.Count -le 3 ) {
Write-Host ("PS $($aux -join '\')>") -NoNewline # -ForegroundColor Cyan
} else {
Write-Host ("PS $($aux[0])\..\$($aux[-2..-1] -join '\')>") -NoNewline # -ForegroundColor Cyan
}
return " "
}