简体   繁体   English

如何在 PowerShell 控制台中更改默认的连字符属性颜色?

[英]How do I change the default hyphenated properties color in PowerShell console?

Every argument that begins with "-" is a grey color.每个以“-”开头的参数都是灰色的。 Is there a setting in Windows 10 to change the value of this color? Windows 10 中是否有设置可以更改此颜色的值?

在此处输入图片说明

I typically don't use the default Blue background and some times it is simply not visible with other background colors.我通常不使用默认的蓝色背景,有时它与其他背景颜色根本不可见。

You can change this with Set-PSReadlineOption .您可以使用Set-PSReadlineOption更改此Set-PSReadlineOption Eg this would change it to red:例如,这会将其更改为红色:

Set-PSReadlineOption -TokenKind parameter -ForegroundColor Red

You might also want to change it for operator and type as these are also Gray by default:您可能还想为 operator 和 type 更改它,因为默认情况下它们也是灰色:

Set-PSReadlineOption -TokenKind operator -ForegroundColor Red
Set-PSReadlineOption -TokenKind type -ForegroundColor Red

The top-rated answer does not work as of 2021 and even at the time of the publication only worked for the immediate window.截至 2021 年,评分最高的答案不起作用,即使在发布时也仅适用于即时窗口。 The more consistent solution is to get the PS profile path with:更一致的解决方案是通过以下方式获取 PS 配置文件路径:

echo $profile

and then add the following command to the file under the returned path:然后将以下命令添加到返回路径下的文件中:

Set-PSReadLineOption -Colors @{Operator = "Green"; Parameter = "Green"; Type = "DarkGreen"}

The profile.ps1 script launches every time PowerShell is executed, therefore keeping the color selection.每次执行 PowerShell 时都会启动 profile.ps1 脚本,因此保留颜色选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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