Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git formatting: truncating with columns

I have the following command to list local branches in the command line:

git for-each-ref --sort=committerdate refs/heads/ --format='%(color:yellow)%(refname:short)%(color:reset);(%(color:green)%(committerdate:relative)%(color:reset));%<(70,trunc)(%(contents:subject)%s)' | column -t -s';'

everything works except for the %<(70,trunc) which just prints out rather than getting applied as a command.

Per the docs:

'%<(<N>[,trunc|ltrunc|mtrunc])': make the next placeholder take at least N columns, padding spaces on the right if necessary. Optionally truncate at the beginning (ltrunc), the middle (mtrunc) or the end (trunc) if the output is longer than N columns. Note that truncating only works correctly with N >= 2.

I don't believe it should matter, but this didn't work in either zsh or bash.

Here's a snippet of how it looks: snippet of formatted git branch list output

like image 709
auerbachb Avatar asked Feb 02 '26 00:02

auerbachb


1 Answers

You are reading the wrong docs. The pretty formats are not what are used in for-each-ref and nothing in the documentation of for-each-ref suggests so. Even if you read the pretty formats help page, you can see that this does not match at all to the placeholders you are using. You have stuff like %s there, not stuff like %(contents:subject). (Btw. you still have %s in your pattern that will always be printed.

As you have %(contents:subject) and %s both in your pattern, I guess you try to transform a git log pattern to a git for-each-ref pattern, but those are totally different which is why the padding / truncating placeholder does not work. It is only available in pretty formats, not in for-each-ref formats.

like image 151
Vampire Avatar answered Feb 03 '26 14:02

Vampire



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!