git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Adding color to git diff output.

From
Linus Torvalds <torvalds@osdl.org>
Date
Apr 12, 2006, 01:03 UTC
Message-ID
<Pine.LNX.4.64.0604111801270.14565@g5.osdl.org>
In-Reply-To
<BAYC1-PASMTP119CAD2588D00764DB3EA3AEC20@CEZ.ICE>
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"
Previous: seanNext: Alex Riesen
Message 5 of 9 in “Adding color to git diff output.”
  1. seanApr 11, 2006
  2. Junio C HamanoApr 11, 2006
  3. Linus TorvaldsApr 12, 2006
  4. seanApr 12, 2006
  5. Linus TorvaldsApr 12, 2006
  6. Alex RiesenApr 12, 2006
  7. Linus TorvaldsApr 12, 2006
  8. Alex RiesenApr 12, 2006
  9. Junio C HamanoApr 12, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.