windows git shell 的 Tput 颜色定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19710074/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tput color definitions for windows git shell
提问by Joey Hipolito
I'm trying to customize my git shell and I found this very interesting articlebut as you can see it use tput
to set color definitions and I can't make it work on windows because tput
wasn't native to windows, are there any alternatives to do th
我正在尝试自定义我的 git shell,我发现了这篇非常有趣的文章,但是正如您所看到的,它用于tput
设置颜色定义,但我无法使其在 Windows 上工作,因为tput
它不是 Windows 原生的,有没有其他替代方法做
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)
回答by VonC
you could use ANSI color escape codes, as in this script:
您可以使用ANSI 颜色转义码,如本脚本所示:
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="3[1;31m"
ORANGE="3[1;33m"
GREEN="3[1;32m"
BLUE="3[1;34m"
PURPLE="3[1;35m"
WHITE="3[1;37m"
BOLD=""
RESET="3[m"
fi
You use it as:
您将其用作:
PS1="\[$WHITE\]\[$BOLD\]\u\[$RESET\]@\[$WHITE\]\[$BOLD\]\h\[$RESET\]:\[3[01;34m\]\[$BOLD\]\w\[$WHITE\]$([[ -n $(git branch 2> /dev/null) ]] && echo \" \[$RESET\]on \")\[$WHITE\]\[$BOLD\]$(parse_git_branch)\[$RESET\]\n$ \[$RESET\]"