How to get ANSI escape codes (colors, text formatting) into `git log` output

问题描述 投票:0回答:0

在您的 Bash 终端中运行:

f="\e[;1;4;5;94m"
F="\e[m"
echo -e "${f}This string is bold, underlined, blinking, bright blue.${F} This is not."

你会看到字符串格式为粗体、下划线、闪烁和亮蓝色,根据我输入的 ANSI 转义码

我想在我的 git log 消息中设置格式文本。我该怎么做?

我目前的尝试,例如这样,只是放入原始字符而不是进行格式化:

# doesn't work
git commit -m "${f}This string is bold, underlined, blinking, bright blue.${F} This is not."

我还尝试将上面第一个 echo 的输出粘贴到我的 git 编辑器(当前是 Sublime Text,因为我在这里展示了如何设置),包括和不包括手动转义代码的字符。也不行。

请注意,这个问题的存在似乎表明我正在尝试做的事情至少是可能ANSI color in git is not displayed correctly--unless I'm missings and hey are just talking关于 git grep 显示 git 控制的文件。更新:我想我误会了:我认为他们在谈论 git log 中的 ANSI 转义码,例如提交哈希本身的着色和粗体。

我为什么要这样做?

我认为让我的 git log 输出中的一些行闪烁并变成蓝色粗体之类的东西会很整洁。我刚刚写了一个 Bash 库 (ansi_text_format_lib.sh) 来允许简单的文本格式化,我想我会在命令行中使用它来做到这一点。

git formatting ansi
© www.soinside.com 2019 - 2024. All rights reserved.