]> Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - bin/svn-wrapper
.gitconfig: Add "dfw" alias for "diff --word-diff"
[dotfiles.git] / bin / svn-wrapper
1 #!/bin/sh
2 # Wrapper script around SVN to support using $PAGER and other handy tools.
3
4 : ${PAGER=missing}
5 export PAGER
6
7 set_colors()
8 {
9 black='\e[0;30m'; lblack='\e[1;30m'
10 red='\e[0;31m'; lred='\e[1;31m'
11 green='\e[0;32m'; lgreen='\e[1;32m'
12 yellow='\e[0;33m'; lyellow='\e[1;33m'
13 blue='\e[0;34m'; lblue='\e[1;34m'
14 purple='\e[0;35m'; lpurple='\e[1;35m'
15 cyan='\e[0;36m'; lcyan='\e[1;36m'
16 grey='\e[0;37m'; lgrey='\e[1;37m'
17 white='\e[0;38m'; lwhite='\e[1;38m'
18 std='\e[m'
19 }
20
21 set_nocolors()
22 {
23 black=; lblack=
24 red=; lred=
25 green=; lgreen=
26 yellow=; lyellow=
27 blue=; lblue=
28 purple=; lpurple=
29 cyan=; lcyan=
30 grey=; lgrey=
31 white=; lwhite=
32 std=
33 }
34
35 # ------------------- #
36 # `main' starts here. #
37 # ------------------- #
38
39 if test -t 1; then
40 # Define colors if stdout is a tty.
41 set_colors
42 test "x${PAGER}" = "xmissing" && PAGER=cat
43 else
44 set_nocolors
45 PAGER=cat
46 fi
47
48 sed_svn_st_color="
49 t dummy_sed_1
50 : dummy_sed_1
51 s@^?\\(......\\)+@+\\1+@
52 s@^?\\(......\\)\\(.*/\\)+@+\\1\\2+@
53 s@^?\\(......\\),@,\\1,@
54 s@^?\\(......\\)\\(.*/\\),@,\\1\\2,@
55 s/^\\(.\\)C/\\1${lred}C${std}/
56 t dummy_sed_2
57 : dummy_sed_2
58 s/^?/${lblue}?${std}/; t
59 s/^M/${lgreen}M${std}/; t
60 s/^A/${lyellow}A${std}/; t
61 s/^X/${lblue}X${std}/; t
62 s/^+/${lyellow}+${std}/; t
63 s/^D/${lyellow}D${std}/; t
64 s/^,/${lred},${std}/; t
65 s/^C/${lred}C${std}/; t
66 s/^I/${purple}I${std}/; t
67 s/^R/${lyellow}R${std}/; t
68 s/^!/${lred}!${std}/; t
69 s/^~/${lwhite}~${std}/; t"
70
71 svn_log_delim="------------------------------------------------------------------------"
72 awk_svn_log_ll='
73 function strip(str) {
74 sub(/^[ \t]+/, "", str);
75 sub(/[ \t]+$/, "", str);
76 return str;
77 }
78 /^r[0-9]+ \| [A-Za-z]+/ {
79 in_rev=1;
80 revnum=strip($1); author=strip($2); date=substr(strip($3), 0, 26);
81 getline;
82 if ($0 == "Changed paths:") {
83 while ($0 != "") {
84 getline;
85 }
86 }
87 getline;
88 };
89 /^.+/ && in_rev {
90 msg=strip($0);
91 while ($0 != "'${svn_log_delim}'") {
92 getline;
93 }
94 if (msg == "'${svn_log_delim}'") {
95 msg = "";
96 }
97 printf("'${yellow}'%s'${std}' %s '${lblack}'(by %s, %s)'${std}'\n", revnum, msg, author, date);
98 };
99 '
100
101 case $1 in
102 cat)
103 exec svn "$@" | $PAGER
104 ;;
105 diff)
106 exec svn "$@" | $PAGER
107 ;;
108 help)
109 exec svn "$@" | $PAGER
110 ;;
111 list|ls)
112 exec svn "$@" | $PAGER
113 ;;
114 ll)
115 shift
116 exec svn log --stop-on-copy "$@" | awk -F"|" "${awk_svn_log_ll}" | $PAGER
117 ;;
118 log)
119 exec svn "$@" | $PAGER
120 ;;
121 status|stat|st)
122 exec svn "$@" | sed "$sed_svn_st_color" | $PAGER
123 ;;
124 *)
125 exec svn "$@"
126 ;;
127 esac
128
129 # vim: ts=2 sts=2 shiftwidth=2 expandtab