]> Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - bin/svn-wrapper
Merge remote-tracking branch 'origin/master' into epic
[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 : ${UNAME=`uname`}
6 export PAGER
7 SED=sed
8 # for Solaris, use GNU versions of core utils
9 if [ "$UNAME" = SunOS ]; then
10 test -x /usr/gnu/bin/sed && SED="/usr/gnu/bin/sed"
11 test -x /usr/xpg4/bin/sed && SED="/usr/xpg4/bin/sed"
12 fi
13
14 set_colors()
15 {
16 black='\e[0;30m'; lblack='\e[1;30m'
17 red='\e[0;31m'; lred='\e[1;31m'
18 green='\e[0;32m'; lgreen='\e[1;32m'
19 yellow='\e[0;33m'; lyellow='\e[1;33m'
20 blue='\e[0;34m'; lblue='\e[1;34m'
21 purple='\e[0;35m'; lpurple='\e[1;35m'
22 cyan='\e[0;36m'; lcyan='\e[1;36m'
23 grey='\e[0;37m'; lgrey='\e[1;37m'
24 white='\e[0;38m'; lwhite='\e[1;38m'
25 std='\e[m'
26 }
27
28 set_nocolors()
29 {
30 black=; lblack=
31 red=; lred=
32 green=; lgreen=
33 yellow=; lyellow=
34 blue=; lblue=
35 purple=; lpurple=
36 cyan=; lcyan=
37 grey=; lgrey=
38 white=; lwhite=
39 std=
40 }
41
42 # ------------------- #
43 # `main' starts here. #
44 # ------------------- #
45
46 if test -t 1; then
47 # Define colors if stdout is a tty.
48 set_colors
49 test "x${PAGER}" = "xmissing" && PAGER=cat
50 else
51 set_nocolors
52 PAGER=cat
53 fi
54
55 sed_svn_st_color="
56 t dummy_sed_1
57 : dummy_sed_1
58 s@^?\\(......\\)+@+\\1+@
59 s@^?\\(......\\)\\(.*/\\)+@+\\1\\2+@
60 s@^?\\(......\\),@,\\1,@
61 s@^?\\(......\\)\\(.*/\\),@,\\1\\2,@
62 s/^\\(.\\)C/\\1${lred}C${std}/
63 t dummy_sed_2
64 : dummy_sed_2
65 s/^?/${lblue}?${std}/; t
66 s/^M/${lgreen}M${std}/; t
67 s/^A/${lyellow}A${std}/; t
68 s/^X/${lblue}X${std}/; t
69 s/^+/${lyellow}+${std}/; t
70 s/^D/${lyellow}D${std}/; t
71 s/^,/${lred},${std}/; t
72 s/^C/${lred}C${std}/; t
73 s/^I/${purple}I${std}/; t
74 s/^R/${lyellow}R${std}/; t
75 s/^!/${lred}!${std}/; t
76 s/^~/${lwhite}~${std}/; t"
77
78 svn_log_delim="------------------------------------------------------------------------"
79 awk_svn_log_ll='
80 function strip(str) {
81 sub(/^[ \t]+/, "", str);
82 sub(/[ \t]+$/, "", str);
83 return str;
84 }
85 /^r[0-9]+ \| [A-Za-z(]+/ {
86 in_rev=1;
87 FS="|";
88 $0=$0 "";
89 revnum=strip($1); author=strip($2); date=strip(substr($3, 0, 26));
90 FS=" ";
91 getline;
92 if ($0 == "Changed paths:") {
93 while ($0 != "") {
94 getline;
95 }
96 }
97 getline;
98 };
99 /^.+/ && in_rev {
100 msg=strip($0);
101 while ($0 != "'${svn_log_delim}'") {
102 getline;
103 }
104 if (msg == "'${svn_log_delim}'") {
105 msg = "";
106 }
107 printf("'${yellow}'%s'${std}' %s '${lblack}'(by %s, %s)'${std}'\n", revnum, msg, author, date);
108 };'
109
110 awk_svn_diff='
111 { str=$0;
112 if (substr(str,1,1) == "@") { str = sprintf("'${lpurple}'%s'${std}'", str); }
113 if (substr(str,1,1) == "-") { str = sprintf("'${lred}'%s'${std}'", str); }
114 if (substr(str,1,1) == "+") { str = sprintf("'${lgreen}'%s'${std}'", str); }
115 if (substr(str,1,1) == "=") { str = sprintf("'${lblue}'%s'${std}'", str); }
116 if (substr(str,1,1) == "I") { str = sprintf("\n'${lblue}'%s'${std}'", str); }
117 print str;
118 };'
119
120 case $1 in
121 cat)
122 exec svn "$@" | $PAGER
123 ;;
124 diff)
125 exec svn "$@" | awk "${awk_svn_diff}" | $PAGER
126 ;;
127 help)
128 exec svn "$@" | $PAGER
129 ;;
130 list|ls)
131 exec svn "$@" | $PAGER
132 ;;
133 ll)
134 shift
135 exec svn log --stop-on-copy "$@" | awk "${awk_svn_log_ll}" | $PAGER
136 ;;
137 log)
138 exec svn "$@" | $PAGER
139 ;;
140 status|stat|st)
141 exec svn "$@" | $SED "$sed_svn_st_color" | $PAGER
142 ;;
143 *)
144 exec svn "$@"
145 ;;
146 esac
147
148 # vim: ts=2 sts=2 shiftwidth=2 expandtab