【问题标题】:change powershell command color更改 powershell 命令颜色
【发布时间】:2019-07-25 19:04:45
【问题描述】:

如何更改 powershell 中的命令颜色?目前它是黄色的,当我使用嵌套在 Intellij 中的 powershell 时,我无法读取白色背景上的黄色命令。

【问题讨论】:

    标签: powershell intellij-idea


    【解决方案1】:

    关于@LotPings 的回答,我解决了我的问题。 powershell 中的以下命令将命令颜色从黄色更改为绿色:

    Set-PSReadLineOption -colors @{ Command = "Green"}
    

    【讨论】:

    • 如果您在代码中添加一些解释会很好。
    • 虽然此解决方案可能有效,但添加一些评论来解释您的答案以及具体解决原始问题的部分总是有用的。
    【解决方案2】:

    查看 cmdlet Get-PSReadlineOptionSet-PSReadlineOption

    你可能想改变:

    Set-PSReadlineOption -Tokenkind Command -BackgroundColor Black
    

    或查看当前设置:

    > Get-PSReadlineOption
    
    EditMode                               : Windows
    ContinuationPrompt                     : >>
    ContinuationPromptForegroundColor      : DarkYellow
    ContinuationPromptBackgroundColor      : DarkMagenta
    ExtraPromptLineCount                   : 0
    AddToHistoryHandler                    :
    CommandValidationHandler               :
    CommandsToValidateScriptBlockArguments : {ForEach-Object, %, Invoke-Command, icm...}
    HistoryNoDuplicates                    : False
    MaximumHistoryCount                    : 4096
    MaximumKillRingCount                   : 10
    HistorySearchCursorMovesToEnd          : False
    ShowToolTips                           : False
    DingTone                               : 1221
    CompletionQueryItems                   : 100
    WordDelimiters                         : ;:,.[]{}()/\|^&*-=+'"–—―
    DingDuration                           : 50
    BellStyle                              : Audible
    HistorySearchCaseSensitive             : False
    ViModeIndicator                        : None
    HistorySavePath                        : C:\Users\LotPings\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\Cons
                                             oleHost_history.txt
    HistorySaveStyle                       : SaveIncrementally
    DefaultTokenForegroundColor            : DarkYellow
    CommentForegroundColor                 : DarkGreen
    KeywordForegroundColor                 : Green
    StringForegroundColor                  : DarkCyan
    OperatorForegroundColor                : DarkGray
    VariableForegroundColor                : Green
    CommandForegroundColor                 : Yellow
    ParameterForegroundColor               : DarkGray
    TypeForegroundColor                    : Gray
    NumberForegroundColor                  : White
    MemberForegroundColor                  : White
    DefaultTokenBackgroundColor            : DarkMagenta
    CommentBackgroundColor                 : DarkMagenta
    KeywordBackgroundColor                 : DarkMagenta
    StringBackgroundColor                  : DarkMagenta
    OperatorBackgroundColor                : DarkMagenta
    VariableBackgroundColor                : DarkMagenta
    CommandBackgroundColor                 : DarkMagenta
    ParameterBackgroundColor               : DarkMagenta
    TypeBackgroundColor                    : DarkMagenta
    NumberBackgroundColor                  : DarkMagenta
    MemberBackgroundColor                  : DarkMagenta
    EmphasisForegroundColor                : Cyan
    EmphasisBackgroundColor                : DarkMagenta
    ErrorForegroundColor                   : Red
    ErrorBackgroundColor                   : DarkMagenta
    

    【讨论】:

    • 我无法使用-Tokenkind 选项。
    【解决方案3】:

    您也可以在终端设置中设置环境变量:

    IntelliJ terminal settings

    然后编辑您的 powershell 配置文件并添加如下内容:

    if ($env:CommandColor) {
        Set-PSReadLineOption -colors @{ Command = $env:CommandColor}
    }
    

    【讨论】:

      【解决方案4】:

      访问Link 了解如何更改 PowerShell 命令颜色。

      此外,您可以使用 Ohmyz 自定义您的 PowerShell,他们也有一些很棒的 插件主题

      【讨论】:

      • 我必须更改哪个条目?我尝试了 $host.UI.RawUI.ForegroundColor,但丑陋的黄色仍然存在
      • 我现在在 Linux 上,所以我无法为你提供合适的 $host 名称,但你可以试试 Ohmyz,它也有很多
      猜你喜欢
      • 2021-12-04
      • 1970-01-01
      • 1970-01-01
      • 2014-02-03
      • 1970-01-01
      • 1970-01-01
      • 2017-10-05
      • 2014-10-31
      • 1970-01-01
      相关资源
      最近更新 更多