Thread (7 messages) flat view 7 messages, 4 authors, 2016-06-15

Re: Adding color to git diff output.

From: Linus Torvalds <torvalds@osdl.org>
Date: 2016-06-15 22:42:23
Subsystem: the rest · Maintainer: Linus Torvalds

Possibly related (same subject, not in this thread)


On Tue, 11 Apr 2006, sean wrote:
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"
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help