Git分支 –format 使用 %(if) 和 %(align)

huangapple go评论47阅读模式
英文:

Git branch --format with %(if) and %(align)

问题

我想改善使用--format参数显示git branch的方式。

首先,我想到了一个解决方案,复制默认格式:

git branch --format "%(if)%(HEAD)%(then)%(HEAD)%(color:green)%(else) %(end) %(refname:short)"

然后,我想在此基础上添加其他信息。我试图使用%(align:...)将它们右对齐:

git branch --format "%(align:50,left)%(if)%(HEAD)%(then)%(HEAD)%(color:green)%(else) %(end)%(refname:short)%(end)AAA"

但结果如下:

git branch --format "%(align:50,left)%(if)%(HEAD)%(then)%(HEAD)%(color:green)%(else) %(end)%(refname:short)%(end)AAA"
  testbranch1                                      AAA
  testbranch2                                      AAA
* testbranch3                                  AAA

任何使用%(if)的地方都会影响对齐。我猜测align函数计算%(if)%(HEAD)内打印的字符数,即使它们没有显示出来。

有解决办法吗?

英文:

I wanted to improve the display of my git branch using --format

First I came up with a solution that copies the default format

git branch --format "%(if)%(HEAD)%(then)%(HEAD)%(color:green)%(else) %(end) %(refname:short)"

Then I wanted to build up on that, adding other infos to the right. I figured I could align them with %(align:...)

git branch --format "%(align:50,left)%(if)%(HEAD)%(then)%(HEAD)%(color:green)%(else) %(end)%(refname:short)%(end)AAA"

But the result is the following:

git branch --format "%(align:50,left)%(if)%(HEAD)%(then)%(HEAD)%(color:green)%(else) %(end)%(refname:short)%(end)AAA"
  testbranch1                                      AAA
  testbranch2                                      AAA
* testbranch3                                  AAA

Any use of %(if) will mess with the align. I guess the align function counts the characters printed inside the %(if)%(HEAD), even if they are not displayed.

Any solution to that?

答案1

得分: 2

您需要将%(align:50,left) ... %(end)%(if) ... %(then) ... %(else) ... %(end) 结构区分开来,它们不能很好地混合使用:

$ git branch --format "%(if)%(HEAD)%(then)%(HEAD)%(color:green)%(else) %(end)%(align:50,left)%(refname:short)%(end)AAA"
英文:

You'd have to get the %(align:50,left) ... %(end) and the %(if) ... %(then) ... %(else) ... %(end) constructs distinct, they don't mix well:

$ git branch --format "%(if)%(HEAD)%(then)%(HEAD)%(color:green)%(else) %(end)%(align:50,left)%(refname:short)%(end)AAA"

huangapple
  • 本文由 发表于 2023年5月22日 22:11:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76307078.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定