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

前端 未结 3 750
梦谈多话
梦谈多话 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 17:08

    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 " "
    }
    

提交回复
热议问题