formatting - 我可以向 mercurial 命令模板添加自定义颜色吗?

标签 formatting mercurial

我想为 hg log 使用自定义模板,如下所示:

hg log --template '{node|short} {desc} [{date|age} by {author}]\'n --color=always

这在默认终端颜色不是很可读,所以例如我想将节点设为红色和 desc 绿色。我怎样才能做到这一点?在 git 中,我可以像这样定义这种格式:

git log --pretty=format:'%Cred%h%Creset %Cgreen%s%Creset [%ar by %an]'

在 mercurial 中是否可能发生类似的事情?

最佳答案

截至 2013 年,Mercurial 直接支持 colors on templates .您也可以在 hg 帮助模板上查看。

您必须在 .hgrc 上激活颜色扩展:

[extensions]
color =

然后添加一些自定义标签以供以后在模板上使用:

[color]
custom.rev = yellow
custom.author = bold

然后使用引用标签的模板(使用 {label('labelname',field)} 而不是 {field}:

hg log --template "{label('custom.rev',node|short)}  {desc}  [{date|age} by {label('custom.author',author)}]\n"

上面的示例以黄色突出显示节点(修订),以粗体蓝色突出提交的作者。与往常一样,您可以在 .hgrc 上创建别名:

[alias]
customlog = log --template "{label('custom.rev',node|short)}  {desc}  [{date|age} by {label('custom.author',author)}]\n"

更新:测试版本 2.5.4。 根据changelog , 这个 works since version 2.5 .

关于formatting - 我可以向 mercurial 命令模板添加自定义颜色吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3625725/

相关文章:

intellij-idea - IntelliJ IDEA 中的变更列表是什么?与什么相比的变化列表?寻求准确的解释

objective-c - Uncrustify:函数名称和行尾大括号之间有空格

c++ - 简单的十六进制/ float 转换

haskell - 如何将 Rational 转换为 "pretty"字符串?

git - 如果使用 Mercurial 或 Git,经常提交文件好吗?

mercurial - 如何在 Snow Leopard 10.6.6 上默认禁用 easy_install 或 pip 构建 ppc?

linux - 在 Bash 中格式化文本输出

python - 'IndexError : tuple index out of range' whith str. 格式

mercurial - 您如何列出 mercurial 存储库中已更改的所有文件,仅限于草稿变更集?

Mercurial merge 分支? (中止 : push creates new remote branches)