From fa1c5c11bd6a51658f41c46e125fd6df037a56ac Mon Sep 17 00:00:00 2001 From: Tony Duckles Date: Sun, 31 Mar 2013 18:28:54 -0500 Subject: [PATCH] bin/svn-wrapper: Add svn-wrapper Create a wrapper script around SVN: * Pipe "svn cat/diff/help/log/status ..." output to $PAGER. * Support color-ified "svn status". * Support "svn ll" alias. --- .bashrc | 3 ++ bin/svn-wrapper | 129 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100755 bin/svn-wrapper diff --git a/.bashrc b/.bashrc index ab9fec4..4ad110f 100644 --- a/.bashrc +++ b/.bashrc @@ -264,6 +264,9 @@ settitle() { printf "\033k%s\033\\" "$@" } +# svn-wrapper +alias svn=~/src/svn-wrapper/svn-wrapper.sh + # ---------------------------------------------------------------------- # BASH COMPLETION # ---------------------------------------------------------------------- diff --git a/bin/svn-wrapper b/bin/svn-wrapper new file mode 100755 index 0000000..931a511 --- /dev/null +++ b/bin/svn-wrapper @@ -0,0 +1,129 @@ +#!/bin/sh +# Wrapper script around SVN to support using $PAGER and other handy tools. + +: ${PAGER=missing} +export PAGER + +set_colors() +{ + black=''; lblack='' + red=''; lred='' + green=''; lgreen='' + yellow=''; lyellow='' + blue=''; lblue='' + purple=''; lpurple='' + cyan=''; lcyan='' + grey=''; lgrey='' + white=''; lwhite='' + std='' +} + +set_nocolors() +{ + black=; lblack= + red=; lred= + green=; lgreen= + yellow=; lyellow= + blue=; lblue= + purple=; lpurple= + cyan=; lcyan= + grey=; lgrey= + white=; lwhite= + std= +} + + # ------------------- # + # `main' starts here. # + # ------------------- # + +if test -t 1; then + # Define colors if stdout is a tty. + set_colors + test "x${PAGER}" = "xmissing" && PAGER=cat +else + set_nocolors + PAGER=cat +fi + +sed_svn_st_color=" + t dummy_sed_1 + : dummy_sed_1 + s@^?\\(......\\)+@+\\1+@ + s@^?\\(......\\)\\(.*/\\)+@+\\1\\2+@ + s@^?\\(......\\),@,\\1,@ + s@^?\\(......\\)\\(.*/\\),@,\\1\\2,@ + s/^\\(.\\)C/\\1${lred}C${std}/ + t dummy_sed_2 + : dummy_sed_2 + s/^?/${lblue}?${std}/; t + s/^M/${lgreen}M${std}/; t + s/^A/${lyellow}A${std}/; t + s/^X/${lblue}X${std}/; t + s/^+/${lyellow}+${std}/; t + s/^D/${lyellow}D${std}/; t + s/^,/${lred},${std}/; t + s/^C/${lred}C${std}/; t + s/^I/${purple}I${std}/; t + s/^R/${lyellow}R${std}/; t + s/^!/${lred}!${std}/; t + s/^~/${lwhite}~${std}/; t" + +svn_log_delim="------------------------------------------------------------------------" +awk_svn_log_ll=' +function strip(str) { + sub(/^[ \t]+/, "", str); + sub(/[ \t]+$/, "", str); + return str; +} +/^r[0-9]+ \| [A-Za-z]+/ { + in_rev=1; + revnum=strip($1); author=strip($2); date=substr(strip($3), 0, 26); + getline; + if ($0 == "Changed paths:") { + while ($0 != "") { + getline; + } + } + getline; +}; +/^.+/ && in_rev { + msg=strip($0); + while ($0 != "'${svn_log_delim}'") { + getline; + } + if (msg == "'${svn_log_delim}'") { + msg = ""; + } + printf("'${yellow}'%s'${std}' %s '${lblack}'(by %s, %s)'${std}'\n", revnum, msg, author, date); +}; +' + +case $1 in + cat) + exec svn "$@" | $PAGER + ;; + diff) + exec svn "$@" | $PAGER + ;; + help) + exec svn "$@" | $PAGER + ;; + list|ls) + exec svn "$@" | $PAGER + ;; + ll) + shift + exec svn log --stop-on-copy "$@" | awk -F"|" "${awk_svn_log_ll}" | $PAGER + ;; + log) + exec svn "$@" | $PAGER + ;; + status|stat|st) + exec svn "$@" | sed "$sed_svn_st_color" | $PAGER + ;; + *) + exec svn "$@" + ;; +esac + +# vim: ts=2 sts=2 shiftwidth=2 expandtab -- 2.47.1