]> Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - bin/svn-wrapper
.vimrc: Git (Fugitive) helpers
[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
104 case $1 in
105 cat)
106 exec svn "$@" | $PAGER
107 ;;
108 diff)
109 exec svn "$@" | $PAGER
110 ;;
111 help)
112 exec svn "$@" | $PAGER
113 ;;
114 list|ls)
115 exec svn "$@" | $PAGER
116 ;;
117 ll)
118 shift
119 exec svn log --stop-on-copy "$@" | awk "${awk_svn_log_ll}" | $PAGER
120 ;;
121 log)
122 exec svn "$@" | $PAGER
123 ;;
124 status|stat|st)
125 exec svn "$@" | sed "$sed_svn_st_color" | $PAGER
126 ;;
127 *)
128 exec svn "$@"
129 ;;
130 esac
131
132 # vim: ts=2 sts=2 shiftwidth=2 expandtab