Custom prompt - debug suspend

I have a custom prompt in my profile.

function prompt {
  $p = Split-Path -leaf -path (Get-Location)
  "$p> "
}

But when I am debugging a script, I noticed the prompt in suspended mode doesn’t have the telltale ‘>>’ I normally see on an non-customized session’s prompt.

PS C:\windows> function testtest () {
>>     $DebugPreference = 'inquire'
>>     Write-Debug "test"
>> }
>>
PS C:\windows> testtest -debug
DEBUG: test
Confirm
Continue with this operation?
[Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): s

PS C:\windows>> 

How would I change my custom prompt to account for this (and any other) case where the prompt is altered for the user?

I think the key is to look at the default prompt code (gc function:prompt):

"PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel
+ 1)) "

It’s the $nestedPromptLevel bit that you’re missing. See how it’s multiplying “>” times the number of prompts, plus one?

Thanks!
I’ve used the following and it works as expected :slight_smile:

function prompt {
  $p = Split-Path -leaf -path (Get-Location)
  "PS $p$('>' * ($nestedPromptLevel + 1)) "
}