How can I change the PowerShell prompt to show just the parent directory and current directory?

前端 未结 3 741
梦谈多话
梦谈多话 2020-12-30 16:23

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         


        
3条回答
  •  自闭症患者
    2020-12-30 16:55

    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.
    

提交回复
热议问题