简体   繁体   中英

How can I change the PowerShell prompt color?

I often find myself lost in a plethora of lines all looking the same. It's hard for me to tell the beginning of the output of my most recent commmand from the output of previous commands.

So, I'd like to change the color of my PowerShell prompt permanently from white text on black background to something else. How can I do this?

From my perspective, the prompt consists of two parts:

  1. path
  2. command

How can I change the color of any of both, but not changing the command's output color?

Alternatively, I'd also very much like to see the path part getting underlined. This would also help in finding my previous commands among lines of other output in order to see where the corresponding other output started. Is this possible?


EDIT

Some comments requested some elaboration on my question, so here's two screenshots depicting the actual/expected situation (note the red line):

actual

在此处输入图像描述

expected

在此处输入图像描述


I'd like to get this for PowerShell 5.x and Core.

So, do you think this is rather a feature request than a query for an existing feature?

After posting my question to the PowerShell team at GitHub, here's the answer to my question:

https://github.com/PowerShell/PowerShell/issues/11136

There's a prompt() hook function available that can be used to customize the prompt.

这是我在上一段中谈到的 powershell 编辑器的图片
I found out that if you use Powershell 5.1, you could use some escaping characters from ASCII table in order to get underlined output:

Write-Host "Hello $([char]27)[4mWorld$([char]27)[24m"

Since Im hesitant that this works perfect, the best solution to underline specific text might be this way:

function Write-Underlined-Host([string]$text,[boolean]$ispath)
{
    if ($ispath -eq $false)
    { 
        Write-Host $text
    }
    else
    {
        $underline = '-'
        $underline_count = $underline * $text.Length

        Write-Host -Object $text
        Write-Host -Object $underline_count
    }
}

$my_path = 'c:\users\jime\desktop'

Write-Underlined-Host -text $my_path -ispath $true

If you look to change your powershell script editor colors (For example if you use ISE), you could change the color of all types.

In ISE: Tools>Options>Script Pane Tokens: (See my attached picture)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM