]> Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - bin/svn-wrapper
.vimrc: Move all vimrc autocmds to a augroup
[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 FS="|";
81 $0=$0 "";
82 revnum=strip($1); author=strip($2); date=strip(substr($3, 0, 26));
83 FS=" ";
84 getline;
85 if ($0 == "Changed paths:") {
86 while ($0 != "") {
87 getline;
88 }
89 }
90 getline;
91 };
92 /^.+/ && in_rev {
93 msg=strip($0);
94 while ($0 != "'${svn_log_delim}'") {
95 getline;
96 }
97 if (msg == "'${svn_log_delim}'") {
98 msg = "";
99 }
100 printf("'${yellow}'%s'${std}' %s '${lblack}'(by %s, %s)'${std}'\n", revnum, msg, author, date);
101 };'
102
103 awk_svn_diff='
104 { str=$0;
105 if (substr(str,1,1) == "@") { str = sprintf("'${lpurple}'%s'${std}'", str); }
106 if (substr(str,1,1) == "-") { str = sprintf("'${lred}'%s'${std}'", str); }
107 if (substr(str,1,1) == "+") { str = sprintf("'${lgreen}'%s'${std}'", str); }
108 if (substr(str,1,1) == "=") { str = sprintf("'${lblue}'%s'${std}'", str); }
109 if (substr(str,1,1) == "I") { str = sprintf("\n'${lblue}'%s'${std}'", str); }
110 print str;
111 };'
112
113 case $1 in
114 cat)
115 exec svn "$@" | $PAGER
116 ;;
117 diff)
118 exec svn "$@" | awk "${awk_svn_diff}" | $PAGER
119 ;;
120 help)
121 exec svn "$@" | $PAGER
122 ;;
123 list|ls)
124 exec svn "$@" | $PAGER
125 ;;
126 ll)
127 shift
128 exec svn log --stop-on-copy "$@" | awk "${awk_svn_log_ll}" | $PAGER
129 ;;
130 log)
131 exec svn "$@" | $PAGER
132 ;;
133 status|stat|st)
134 exec svn "$@" | sed "$sed_svn_st_color" | $PAGER
135 ;;
136 *)
137 exec svn "$@"
138 ;;
139 esac
140
141 # vim: ts=2 sts=2 shiftwidth=2 expandtab