chiark / gitweb /
Only print the progress message if on a TTY
[stgit] / contrib / diffcol.sh
1 #!/bin/sh
2
3 # Code copied from Quilt (http://savannah.nongnu.org/projects/quilt)
4 #
5 # Copyright 2006 - the Quilt authors
6 #
7 #  This script is free software; you can redistribute it and/or modify
8 #  it under the terms of the GNU General Public License version 2 as
9 #  published by the Free Software Foundation.
10
11 setup_colors()
12 {
13         local C="diffhdr=1;36:diffhdradd=1;32:diffadd=32:diffhdrmod=1;35:diffmod=35:diffhdrrem=1;31:diffrem=31:diffhunk=36:diffctx=34:diffcctx=33:default=0"
14         [ -n "$DIFF_COLORS" ] && C="$C:$DIFF_COLORS"
15
16         C=${C//=/=\'$'\e'[}
17         C=col${C//:/m\'; col}m\'
18         #coldefault=$(tput op)
19         eval $C
20 }
21
22 setup_colors
23
24 gawk '{
25         if (/^(Index:|diff --git) /)
26                 print "'$coldiffhdr'" $0 "'$coldefault'"
27         else if (/^======*$/)
28                 print "'$coldiffhdr'" $0 "'$coldefault'"
29         else if (/^\+\+\+/)
30                 print "'$coldiffhdradd'" $0 "'$coldefault'"
31         else if (/^\*\*\*/)
32                 print "'$coldiffhdrmod'" $0 "'$coldefault'"
33         else if (/^---/)
34                 print "'$coldiffhdrrem'" $0 "'$coldefault'"
35         else if (/^(\+|new( file)? mode )/)
36                 print "'$coldiffadd'" $0 "'$coldefault'"
37         else if (/^(-|(deleted file|old) mode )/)
38                 print "'$coldiffrem'" $0 "'$coldefault'"
39         else if (/^!/)
40                 print "'$coldiffmod'" $0 "'$coldefault'"
41         else if (/^@@ \-[0-9]+(,[0-9]+)? \+[0-9]+(,[0-9]+)? @@/)
42                 print gensub(/^(@@[^@]*@@)([ \t]*)(.*)/,
43                         "'$coldiffhunk'" "\\1" "'$coldefault'" \
44                         "\\2" \
45                         "'$coldiffctx'" "\\3" "'$coldefault'", "")
46         else if (/^\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/)
47                 print "'$coldiffcctx'" $0 "'$coldefault'"
48         else {
49                 print
50         }
51 }' $1 | less -R -S