[PATCH] git-status: support always/auto/never in colorization
- From
Jeff King <peff@peff.net>
- Date
- Aug 5, 2006, 23:57 UTC
- Message-ID
- <20060805235756.GA15075@coredump.intra.peff.net>
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