我只想让PowerShell成为白色背景上的黑色文字。但是,PowerShell v5突出显示了我的命令,并使它们变黄,这是不可能看到的。有没有办法在PowerShell中关闭所有语法高亮?
答案 0 :(得分:9)
可以通过Set-PSReadlineOption
修改PowerShell v5中的语法着色。以下命令将注释的foregound和背景颜色设置为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
...
将所有这些语句放入profile,以便每次启动PowerShell时都应用它们,例如:
$HOME\Documents\WindowsPowerShell\profile.ps1
答案 1 :(得分: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"
答案 2 :(得分:1)
答案 3 :(得分:0)
以下是我在osx中为那些让我烦恼的事情做的事情:
$a = get-psreadlineoption | select ErrorBackgroundColor
$clear = $a.ErrorBackgroundColor
'command','number','operator','member' |
foreach { set-psreadlineoption $_ black $clear }
答案 4 :(得分:0)
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 }
答案 5 :(得分:0)
语法在最近的更新中已更改。现在,旧语法会给您带来讨厌的错误消息:
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'}