powershell - 如何关闭控制台中的语法高亮?

标签 powershell syntax-highlighting powershell-5.0 psreadline

我只希望 PowerShell 是白色背景上的黑色文本。但是,PowerShell v5 突出显示了我的命令并使它们变黄,这是不可能看到的。有没有办法在 PowerShell 中关闭所有语法高亮?

最佳答案

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
...

将所有这些陈述放入您的 profile每次启动 PowerShell 时都应用它们,例如:
$HOME\Documents\WindowsPowerShell\profile.ps1

关于powershell - 如何关闭控制台中的语法高亮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35246709/

相关文章:

r - 如何使用highlight.js突出显示所有R函数名称?

c++ - Visual Studio 2010 中好的 C++ 主题的集合?

powershell - 为什么Write-Output在PowerShell类方法中不起作用?

powershell - 运行 PowerShell 时强制执行 ErrorActionPreference?

powershell - 使用动态构造的排除模式数组,使用 Get-ChildItem -Exclude 过滤子文件夹

powershell - 无法使用 PowerShell 在任务计划程序中创建任务

powershell - 处理带有空格的名称

Powershell:打开 cmd.exe,然后在 cmd 上运行命令

vim - 当 Vim/Neovim 高亮显示与文本相同的颜色时无法阅读

c# - 具有多个自定义属性的 PowerShell 方法