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
These other replies were much more involved. Even so, here's mine. If it's greater than 30 characters, we shorten the path. Done.
Function Prompt {
If ("$($executionContext.SessionState.Path.CurrentLocation)>".Length -le 30) {
"PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) ";
} Else {
"PS ...\$(Split-Path -Path $executionContext.SessionState.Path.CurrentLocation -Leaf)$('>' * ($nestedPromptLevel + 1)) ";
} # End If.
} # End Function: Prompt.