git-prompt.sh 输出中的颜色
Colors in git-prompt.sh output
我正在尝试修改 git-prompt.sh 以将 */+ 回购状态指示器替换为更具可读性的版本,例如 "changes" / "staged files"。
只需更改文本就足够了,但我还需要不同的颜色。简单地将一些颜色转义序列如 \[\e[33m\]
粘贴到状态描述字符串中是行不通的;转义序列等只是转储到输出中。
当从 git-prompt.sh 脚本输出时,有什么方法可以让 bash 理解颜色?
看来你必须使用 tput
颜色。
示例来自 https://gist.github.com/trey/2722934#gistcomment-1835441
YELLOW="\[$(tput setaf 3)\]"
RESET="\[$(tput sgr0)\]"
PS1="\h:\W \u$(__git_ps1 \" ${YELLOW}(%s)${RESET} \")$ "
另请参阅 https://raymii.org/s/snippets/Bash_Bits_Add_Color_Output_To_Your_Scripts.html and https://unix.stackexchange.com/questions/269077/tput-setaf-color-table-how-to-determine-color-codes 了解颜色列表。
我正在尝试修改 git-prompt.sh 以将 */+ 回购状态指示器替换为更具可读性的版本,例如 "changes" / "staged files"。
只需更改文本就足够了,但我还需要不同的颜色。简单地将一些颜色转义序列如 \[\e[33m\]
粘贴到状态描述字符串中是行不通的;转义序列等只是转储到输出中。
当从 git-prompt.sh 脚本输出时,有什么方法可以让 bash 理解颜色?
看来你必须使用 tput
颜色。
示例来自 https://gist.github.com/trey/2722934#gistcomment-1835441
YELLOW="\[$(tput setaf 3)\]"
RESET="\[$(tput sgr0)\]"
PS1="\h:\W \u$(__git_ps1 \" ${YELLOW}(%s)${RESET} \")$ "
另请参阅 https://raymii.org/s/snippets/Bash_Bits_Add_Color_Output_To_Your_Scripts.html and https://unix.stackexchange.com/questions/269077/tput-setaf-color-table-how-to-determine-color-codes 了解颜色列表。