我写了一个 git status 的变体。如何使用 git status 用于分阶段和未分阶段更改的绿色和红色来为我的输出着色?最好是找到红色和绿色的运行时 git 定义,但这并不那么重要:硬编码的解决方案就可以了。
Git 可能会使用 ANSI 转义码:https://en.wikipedia.org/wiki/ANSI_escape_code
这通常意味着您在
-e
中使用 echo
或在 printf 中使用 %b (使用适用于 Windows 2.43.0 的 Git 进行测试):
declare color_red="\\e[1;31m"
declare color_none="\\e[0m"
declare color_green="\\e[1;32m"
echo -e "${color_red}RED${color_none}"
printf "%bRED%b" "${color_red}" "${color_none}"
color.status.<slot>
和布尔值 color.status
处理:我没有使用 git config
命令找到默认值。