git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Tom Hale <tom@hale.ee>, git <git@vger.kernel.org>
Subject: Re: %C(auto) not working as expected
Date: Sun, 9 Oct 2016 08:47:25 +0200	[thread overview]
Message-ID: <f35965e9-2901-b9b5-92e5-9bc7fe673637@web.de> (raw)
In-Reply-To: <cb81631e-9623-9020-f955-ec215b493a50@hale.ee>

Am 09.10.2016 um 07:43 schrieb Tom Hale:
> $ ~/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é


  reply	other threads:[~2016-10-09  6:48 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-09  5:43 %C(auto) not working as expected Tom Hale
2016-10-09  6:47 ` René Scharfe [this message]
2016-10-09 10:04   ` Tom Hale
2016-10-09 13:24     ` René Scharfe
2016-10-09 23:46       ` Jeff King
2016-10-10  9:26         ` Duy Nguyen
2016-10-10 14:28           ` Jeff King
2016-10-10 15:15             ` [PATCH] pretty: respect color settings for %C placeholders Jeff King
2016-10-10 17:09               ` René Scharfe
2016-10-10 17:42                 ` Jeff King
2016-10-10 19:59                   ` René Scharfe
2016-10-10 20:04                     ` Jeff King
2016-10-10 18:52               ` Junio C Hamano
2016-10-10 18:59                 ` Jeff King
2016-10-10 20:54                   ` Jeff King
2016-10-11 10:59               ` Duy Nguyen
2016-10-25 12:52             ` %C(auto) not working as expected Duy Nguyen
2016-10-25 12:58               ` Jeff King
2016-10-25 13:02                 ` Duy Nguyen
2016-10-10 20:52         ` René Scharfe
2016-10-10 20:55           ` Jeff King
2016-10-11  3:41             ` [PATCH v2] pretty: fix document link for color specification René Scharfe
2016-10-11  4:45               ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f35965e9-2901-b9b5-92e5-9bc7fe673637@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    --cc=tom@hale.ee \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).