git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: %C(auto) not working as expected

From
René Scharfe <l.s.r@web.de>
Date
Oct 9, 2016, 06:47 UTC
Message-ID
<f35965e9-2901-b9b5-92e5-9bc7fe673637@web.de>
In-Reply-To
<cb81631e-9623-9020-f955-ec215b493a50@hale.ee>
Am 09.10.2016 um 07:43 schrieb Tom Hale:
Show 16 quoted lines
> $ ~/repo/git/git --version
> git version 2.10.0.GIT
>
> The `git-log` man page says:
>
> `auto` alone (i.e.  %C(auto)) will turn on auto coloring on the next
> placeholders until the color is switched again.
>
> In this example:
>
> http://i.imgur.com/y3yLxk7.png
>
> I turn on auto colouring for green, but it seems that this is not being
> respected when piped through `cat`.
>
> Am I misunderstanding the manual?
So this colors the ref name decoration and the short hash:
	$ git log -n1 --format="%C(auto)%d %C(auto)%Cgreen%h"
And this only colors the short hash:
	$ git log -n1 --format="%C(auto)%d %C(auto)%Cgreen%h" | cat

%C(auto) respects the color-related configuration settings; that's mentioned on the man page for git log in the section on %C(...). You probably have color.ui=auto or color.diff=auto in your config, which means that output to terminals is to be colored, but output to files and pipes isn't. You could override that setting e.g. by adding the command line option --color=always.

%Cgreen emits color codes unconditionally. %C(auto,green) would respect the config settings.

Your second %C(auto) has no effect because it is overridden by the immediately following %Cgreen.

You may want to add a %Creset at the end to avoid colors bleeding out over the end of the line. You can see that happening e.g. with:

	$ git log -n3 --format="normal %C(green)green" | cat
Without cat bash seems to add a reset automatically.
René
Previous: Tom HaleNext: Tom Hale
Message 2 of 23 in “%C(auto) not working as expected”
  1. Tom HaleOct 9, 2016
  2. René ScharfeOct 9, 2016
  3. Tom HaleOct 9, 2016
  4. René ScharfeOct 9, 2016
  5. Jeff KingOct 9, 2016
  6. Duy NguyenOct 10, 2016
  7. Jeff KingOct 10, 2016
  8. pretty: respect color settings for %C placeholdersJeff King, Oct 10, 2016
  9. René ScharfeOct 10, 2016
  10. Jeff KingOct 10, 2016
  11. René ScharfeOct 10, 2016
  12. Jeff KingOct 10, 2016
  13. Junio C HamanoOct 10, 2016
  14. Jeff KingOct 10, 2016
  15. Jeff KingOct 10, 2016
  16. Duy NguyenOct 11, 2016
  17. Duy NguyenOct 25, 2016
  18. Jeff KingOct 25, 2016
  19. Duy NguyenOct 25, 2016
  20. René ScharfeOct 10, 2016
  21. Jeff KingOct 10, 2016
  22. pretty: fix document link for color specificationRené Scharfe, Oct 11, 2016
  23. Jeff KingOct 11, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.