【问题标题】:Command line and output a different color in Mac terminal?命令行并在Mac终端中输出不同的颜色?
【发布时间】:2015-09-25 08:30:00
【问题描述】:

有什么方法可以让 Mac 终端上的命令行提示符的颜色与输出不同?现在,所有东西都是相同的颜色,有时让人难以理解。

虽然我使用过 Vagrant,但现在我希望我的命令行能够从标准 Mac 终端中的其余输出文本中突出显示。我确实知道如何改变它的颜色,但那是终端输出和提示之间共享的颜色

【问题讨论】:

  • 是的,有可能。它是如何完成的将取决于您运行的 shell:bash、zsh、csh、ksh 等。它们的配置都不同,所以如果您能告诉我们您正在使用哪个,它将帮助某人提供答案。

标签: macos command-line terminal stdout prompt


【解决方案1】:

我正在使用iTerm2,并使用iterm2colorschemes 自定义配色方案。

【讨论】:

    【解决方案2】:

    您可以通过修改 bash_profile 来更改它,并在其中包含您的偏好:

    选项 1 结果:[time user_in_red@host_in_purple ~/Directory_in_your_computer_color ] $ commands_with_your_computer_settings

    PS1="[\t \[$(tput setaf 9)\]\u\[$(tput setaf 15)\]@\[$(tput setaf 12)\]\h \[$(tput sgr0)\]\w ] \$ "

    选项 2 结果:@User_green_color~/Directory_in_green _color $ your_commands_with_your_computer_settings

    PS1="@\[$(tput setaf 2)\]\u\[$(tput setaf 2)\]\w\$(tput sgr0)\] \$ "

    您可以根据需要创建自己的设置。例如,这是颜色 2 绿色的用户。

    [$(tput setaf 2)\]\u
    

    为了修改你的 bash_profile 在你的终端输入这个。

    nano ~/.bash_profile

    打开后粘贴您的设置、上述选项之一或您创建的选项。

    保存并关闭它。 Control+x 关闭它,选择“y”保存更改,然后输入关闭它。

    关闭您的终端并打开一个新终端,您应该能够看到您的更改。

    其他颜色:

    0 – 黑色。

    1 – 红色。

    2 - 绿色。

    3 – 黄色。

    4 – 蓝色。

    5 – 洋红色。

    6 – 青色。

    7 – 白色。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-20
      • 2015-12-26
      • 2016-07-04
      • 1970-01-01
      • 2013-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多