I'm using git for-each-ref
as a git alias to display a branch name and the subject of the last commit on that branch. That said, it's hard to tell where the branch name ends and the commit message subject starts, so I'm trying to colourize the branch name to more easily tell the difference between the two. Below is the working alias without colour:
[alias]
logbranch = for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short) %(subject)'
To add colour, I tried using shell colour escapes (I'm using bash) like so:
[alias]
logbranch = for-each-ref --sort=-committerdate refs/heads/ --format='[\033[0;31m]%(refname:short)[\e[m] %(subject)'
which gives me a git config error. I also tried replacing the single quotes with double quotes, and escaping the square brackets, but no dice.
Ideas?
Git 1.9/2.0 (Q1 2014) will introduce color formatting for git for-each-ref
.
See commit fddb74c from Ramkumar Ramachandra (artagnon):
for-each-ref
: introduce %(color:...)
for colorEnhance '
git for-each-ref
' with color formatting options.
You can now use the following format in for-each-ref:
%(color:green)%(refname:short)%(color:reset)
where color names are described in
color.branch.*
.
With Git 2.15 (Q4 2017), you will be able to turn those colors on or off.
See commit 0c88bf5 (03 Oct 2017) by Jeff King (peff
).
(Merged 04 Oct 2017)
provide
--color
option for all ref-filter usersWhen ref-filter learned about want_color() in 11b087a (
ref-filter
: consult want_color() before emitting colors, 2017-07-13), it became useful to be able to turn colors off and on for specific commands. Forgit-branch
, you can do so with--color
/--no-color
.But for
git-for-each-ref
andgit-tag
, the other users of ref-filter, you have no option except to tweak the "color.ui
" config setting. Let's give both of these commands the usual color command-line options.This is a bit more obvious as a method for overriding the config. And it also prepares us for the behavior of "
always
" changing (so that we are still left with a way of forcing color when our output goes to a non-terminal).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With