我只想让 PowerShell 成为白色背景上的黑色文本。但是,PowerShell v5 会突出显示我的命令并将它们变成黄色,这是无法看到的。有没有办法在 PowerShell 中关闭所有语法突出显示?
问问题
9109 次
6 回答
9
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
于 2016-02-07T01:07:01.840 回答
5
例如,如何关闭所有语法高亮:
Set-PSReadlineOption -TokenKind Parameter -ForegroundColor DarkYellow -BackgroundColor DarkMagenta
Set-PSReadlineOption -TokenKind String -ForegroundColor DarkYellow -BackgroundColor DarkMagenta
Set-PSReadlineOption -TokenKind Operator -ForegroundColor DarkYellow -BackgroundColor DarkMagenta
Set-PSReadlineOption -TokenKind Type -ForegroundColor DarkYellow -BackgroundColor DarkMagenta
Set-PSReadlineOption -TokenKind Variable -ForegroundColor DarkYellow -BackgroundColor DarkMagenta
Set-PSReadlineOption -TokenKind Number -ForegroundColor DarkYellow -BackgroundColor DarkMagenta
Set-PSReadlineOption -TokenKind Member -ForegroundColor DarkYellow -BackgroundColor DarkMagenta
Set-PSReadlineOption -TokenKind Command -ForegroundColor DarkYellow -BackgroundColor DarkMagenta
Set-PSReadlineOption -TokenKind Comment -ForegroundColor DarkYellow -BackgroundColor DarkMagenta
Set-PSReadlineOption -TokenKind Keyword -ForegroundColor DarkYellow -BackgroundColor DarkMagenta
Set-PSReadlineOption -ContinuationPromptForegroundColor DarkYellow -ContinuationPromptBackgroundColor DarkMagenta
Set-PSReadlineOption -EmphasisForegroundColor DarkYellow -EmphasisBackgroundColor DarkMagenta
Set-PSReadlineOption -ErrorForegroundColor DarkYellow -ErrorBackgroundColor DarkMagenta
(Get-Host).PrivateData.ErrorForegroundColor="DarkYellow"
(Get-Host).PrivateData.ErrorBackgroundColor="DarkMagenta"
(Get-Host).PrivateData.WarningForegroundColor="DarkYellow"
(Get-Host).PrivateData.WarningBackgroundColor="DarkMagenta"
(Get-Host).PrivateData.DebugForegroundColor="DarkYellow"
(Get-Host).PrivateData.DebugBackgroundColor="DarkMagenta"
(Get-Host).PrivateData.VerboseForegroundColor="DarkYellow"
(Get-Host).PrivateData.VerboseBackgroundColor="DarkMagenta"
(Get-Host).PrivateData.ProgressForegroundColor="DarkYellow"
(Get-Host).PrivateData.ProgressBackgroundColor="DarkMagenta"
于 2016-10-08T20:31:40.217 回答
5
语法在最近的更新中发生了变化。旧语法现在会给你一个讨厌的错误信息:
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'}
于 2019-11-27T07:40:39.183 回答
4
Set-PSReadLineOption -Colors @{
Command = 'White'
Number = 'White'
Member = 'White'
Operator = 'White'
Type = 'White'
Variable = 'White'
Parameter = 'White'
ContinuationPrompt = 'White'
Default = 'White'
}
于 2021-04-05T14:58:36.727 回答
1
get-help set-psreadlineoption
https://docs.microsoft.com/en-us/powershell/module/PSReadline/Set-PSReadlineOption
'None', 'Comment', 'Keyword', 'String', 'Operator',
'Variable', 'Command', 'Parameter', 'Type', 'Number', 'Member' |
foreach { set-psreadlineoption $_ black white }
于 2018-05-18T18:57:41.493 回答
0
以下是我在 osx 中针对立即困扰我的事情的做法:
$a = get-psreadlineoption | select ErrorBackgroundColor
$clear = $a.ErrorBackgroundColor
'command','number','operator','member' |
foreach { set-psreadlineoption $_ black $clear }
于 2017-05-27T01:04:21.600 回答