【问题标题】:How to make Macbook Terminal text less transparent如何使 Macbook 终端文本不那么透明
【发布时间】:2018-09-01 03:47:37
【问题描述】:

我最近修改了我的 .bash_profile 以更改终端命令提示符的颜色和格式。不幸的是,在这样做的过程中,我还导致我输入的任何文本都以非常透明的阴影显示:

以下是我的 .bash_profile 的内容:

PS1="\[\033[0;35m\]\u\[\033[1;33m\]@\[\033[1;33m\]\w\[\033[0;32m\]\$ "
export PS1;

export CLICOLOR=1
export LSCOLORS=Gafxcxdxbxegedabagacad

如何修改我的 .bash_profile 文件以使所有文本与图像中显示的粗体-绿色和粗体-黄色文本一样亮/粗体?

【问题讨论】:

    标签: bash macos terminal


    【解决方案1】:

    使用转义码设置 PS1 变量很繁琐,而且常常有副作用。我多年来一直这样做,并且换行经常被打破。我在终端窗口中测试了你的 PS1。似乎有些东西没有正确终止,因为颜色渗入下一行。我使用 tput 设置 PS1,这使得作业更具可读性。这是我在 .bash_profile 中的内容:

    set_prompt() {
    local red=$(tput setaf 1)
    local green=$(tput setaf 2)
    local yellow=$(tput setaf 3)
    local blue=$(tput setaf 4)
    local magenta=$(tput setaf 5)
    local cyan=$(tput setaf 6)
    local white=$(tput setaf 7)
    local reset=$(tput sgr0)
    
    if [ ${UID} -eq 0 ]; then
        # user is red when we are root
        export PS1="\[$red\]\u\[$white\]@\[$green\]\h\[$white\]:\[$yellow\]\w [$reset\]$ "
    else
        export PS1="\[$blue\]\u\[$white\]@\[$green\]\h\[$white\]:\[$yellow\]\w\[$reset\]$ "
    fi;
    

    }

    # Don't set the prompt for dumb terminals
    if [ ${TERM+x} -a "${TERM-}" != "dumb" ]; then
        set_prompt
    fi
    

    【讨论】:

      【解决方案2】:

      较亮的文本来自这个块,它设置了粗体属性1

      \[\033[1;33m\]
      

      由于您在末尾省略了粗体,因此文本变得暗淡:

      \[\033[0;32m\]
      

      3233 分别选择颜色 greenyellow,但没有bold 属性,大多数终端显示为棕色

      进一步阅读

      【讨论】:

        【解决方案3】:

        我也在使用 macbook,但我不使用默认终端应用程序。我用的是iTerm,它真的更灵活,可以配置成你想要的显示方式。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-04-03
          • 2012-11-07
          • 2015-06-20
          • 1970-01-01
          • 2021-12-19
          相关资源
          最近更新 更多