【问题标题】:Tput color definitions for windows git shellWindows git shell 的 Tput 颜色定义
【发布时间】:2013-11-11 16:03:05
【问题描述】:

我正在尝试自定义我的 git shell,我发现这很有趣 article 但是你可以看到它使用 tput 来设置颜色定义,我无法让它在 Windows 上工作,因为 tput 是'不是 Windows 原生的,有没有其他方法可以做 th

BLACK=$(tput setaf 0)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
LIME_YELLOW=$(tput setaf 190)
POWDER_BLUE=$(tput setaf 153)
BLUE=$(tput setaf 4)
MAGENTA=$(tput setaf 5)
CYAN=$(tput setaf 6)
WHITE=$(tput setaf 7)
BRIGHT=$(tput bold)
NORMAL=$(tput sgr0)
BLINK=$(tput blink)
REVERSE=$(tput smso)
UNDERLINE=$(tput smul)

【问题讨论】:

    标签: git shell workflow


    【解决方案1】:

    您可以使用ANSI color escape codes,如this script

    if tput setaf 1 &> /dev/null; then
        tput sgr0
        if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then
          MAGENTA=$(tput setaf 9)
          ORANGE=$(tput setaf 172)
          GREEN=$(tput setaf 190)
          PURPLE=$(tput setaf 141)
          WHITE=$(tput setaf 256)
        else
          MAGENTA=$(tput setaf 5)
          ORANGE=$(tput setaf 4)
          GREEN=$(tput setaf 2)
          PURPLE=$(tput setaf 1)
          WHITE=$(tput setaf 7)
        fi
        BOLD=$(tput bold)
        RESET=$(tput sgr0)
    else
        MAGENTA="\033[1;31m"
        ORANGE="\033[1;33m"
        GREEN="\033[1;32m"
        BLUE="\033[1;34m"
        PURPLE="\033[1;35m"
        WHITE="\033[1;37m"
        BOLD=""
        RESET="\033[m"
    fi
    

    您将其用作:

    PS1="\[$WHITE\]\[$BOLD\]\u\[$RESET\]@\[$WHITE\]\[$BOLD\]\h\[$RESET\]:\[\033[01;34m\]\[$BOLD\]\w\[$WHITE\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" \[$RESET\]on \")\[$WHITE\]\[$BOLD\]\$(parse_git_branch)\[$RESET\]\n\$ \[$RESET\]"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-30
      • 1970-01-01
      • 1970-01-01
      • 2015-01-29
      • 2015-04-11
      • 1970-01-01
      • 2017-05-02
      • 2022-09-29
      相关资源
      最近更新 更多