我只想让PowerShell成为白色背景上的黑色文本。然而,PowerShell v5突出显示了我的命令,并使它们变黄,这是不可能看到的。有办法关闭PowerShell中的所有语法高亮显示吗?
发布于 2016-02-07 01:07:01
PowerShell v5中的语法着色可以通过Set-PSReadlineOption进行修改。以下命令将注释的前色和背景色设置为shell前景和背景色:
Set-PSReadlineOption -TokenKind Comment -ForegroundColor $Host.UI.RawUI.ForegroundColor -BackgroundColor $Host.UI.RawUI.BackgroundColor或者只是黑白相间:
Set-PSReadlineOption -TokenKind Comment -ForegroundColor Black -BackgroundColor White您需要对所有TokenKind值执行此操作,以完全删除语法着色。
如果还想改变输出流的颜色,可以通过主机的PrivateData对象的属性来做到这一点:
$Host.PrivateData.WarningForegroundColor = $Host.UI.RawUI.ForegroundColor
$Host.PrivateData.WarningBackgroundColor = $Host.UI.RawUI.BackgroundColor
...将所有这些语句放入您的配置文件中,以便在每次启动PowerShell时应用这些语句,例如:
$HOME\Documents\WindowsPowerShell\profile.ps1发布于 2019-11-27 07:40:39
在最近的更新中,语法发生了变化。旧的语法现在将给您一个讨厌的错误消息:
Set-PSReadLineOption : A positional parameter cannot be found that accepts argument 'Command'.
At line:1 char:1
+ Set-PSReadLineOption 'Command' white black
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-PSReadLineOption], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.SetPSReadLineOption 或
Set-PSReadLineOption : A parameter cannot be found that matches parameter name 'TokenKind'.
At line:1 char:22
+ Set-PSReadlineOption -TokenKind Comment -ForegroundColor 'black' -Bac ...
+ ~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-PSReadLineOption], Par ameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.SetP SReadLineOption更新的语法似乎要求您传递一个新设置的字典。
Set-PSReadLineOption -Colors @{None='black';Comment='black';Keyword='black';String='black';Operator='black';Variable='black';Command='black';Parameter='black';Type='black';Number='black';Member='black'}如果你
Set-PSReadLineOption: 'None' is not a valid color property(这显然意味着您在Linux上),取出None='black';,如下所示:
Set-PSReadLineOption -Colors @{Comment='black';Keyword='black';String='black';Operator='black';Variable='black';Command='black';Parameter='black';Type='black';Number='black';Member='black'} 发布于 2021-04-05 14:58:36
Set-PSReadLineOption -Colors @{
Command = 'White'
Number = 'White'
Member = 'White'
Operator = 'White'
Type = 'White'
Variable = 'White'
Parameter = 'White'
ContinuationPrompt = 'White'
Default = 'White'
}https://stackoverflow.com/questions/35246709
复制相似问题