Re: Adding color to git diff output.
On Tue, 11 Apr 2006, sean wrote:
Show 13 quoted lines
>
> What I have is a script ~/bin/gitcdiff:
>
> #!/bin/sh
> tty -s <&1 || exec cat
> colordiff | less -RS
>
> And then setting GIT_DIFF_PAGER="~/bin/gitcdiff". When piping to a file
> it just uses cat, but when the output is a terminal device it uses the
> colordiff.
>
> I thought about integrating that logic into git-diff.sh, but i'm not sure
> it's always appropriate.
Yeah, that's close to what I'd have suggested:
Linus
----
diff --git a/git-diff.sh b/git-diff.sh
index dc0dd31..f0bea80 100755
--- a/git-diff.sh
+++ b/git-diff.sh
@@ -69,4 +69,8 @@ case "$rev" in
;;
esac
+if [ "$GIT_DIFF_PAGER" ] && tty -s <&1; then
+ cmd="$cmd | $GIT_DIFF_PAGER"
+fi
+
eval "$cmd"