Git development
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: [PATCH] git-status: support always/auto/never in colorization
Date: Sat, 5 Aug 2006 19:57:56 -0400	[thread overview]
Message-ID: <20060805235756.GA15075@coredump.intra.peff.net> (raw)

Signed-off-by: Jeff King <peff@peff.net>
---
This is on top of the previous two patches:
    git-status: colorize status output (me)
    git-status: do not use colors all the time (Matthias)

I was hoping to join the term selection logic with the diff.color logic
in git_config_termbool or similar (and a git-repo-config --termbool),
but unfortunately that doesn't work since git-repo-config can't do an
isatty test (since we call it as `git-repo-config`). In general, config
parsing is a little awkward (and inefficient) in sh. Is there any
interest in me converting git-commit/git-status to C builtins (I know
Johannes will be happy...)?

 Documentation/config.txt |    4 +++-
 git-commit.sh            |   13 ++++++++-----
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 83f4627..43766bd 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -224,7 +224,9 @@ showbranch.default::
 
 status.color::
 	A boolean to enable/disable color in the output of
-	gitlink:git-status[1]. Defaults to false.
+	gitlink:git-status[1]. May be set to `true` (or `always`),
+	`false` (or `never`) or `auto`, in which case colors are used
+	only when the output is to a terminal. Defaults to false.
 
 status.color.<slot>::
 	Use customized color for status colorization. `<slot>` is
diff --git a/git-commit.sh b/git-commit.sh
index ad0cbb1..2ab1974 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -20,11 +20,14 @@ case "$0" in
 *status)
 	status_only=t
 	unmerged_ok_if_status=--unmerged
-	[ "`git-repo-config --bool --get status.color`" = 'true' ] &&
-		([ -t 1 ] || (
-			[ -n "$GIT_PAGER_IN_USE" ] &&
-			[ "`git-repo-config --bool --get pager.color`" != 'false' ]
-		)) && color=true
+	case "`git-repo-config --get status.color`" in
+	  always) color=true ;;
+	  never ) color=false ;;
+	  auto  ) test -t 1 -o \( -n "$GIT_PAGER_IN_USE" -a \
+		     "`git-repo-config --bool --get pager.color`" != false \) \
+		  && color=true ;;
+	  *     ) color="`git-repo-config --bool --get status.color`" ;;
+	esac
 	eval `git-repo-config --get-regexp status.color. \
 	      | while read k v; do
 	          echo color_${k#status.color.}=$v
-- 
1.4.2.rc3.gf3bd-dirty

             reply	other threads:[~2006-08-05 23:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-05 23:57 Jeff King [this message]
2006-08-06  0:38 ` [PATCH] git-status: support always/auto/never in colorization Junio C Hamano

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

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

  git send-email \
    --in-reply-to=20060805235756.GA15075@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox