Mercurial > index.cgi > dotfiles
comparison bin/hgeditor @ 84:fe021064d723
Adding 'hgeditor' to repo & environment
author | Steve Huston <huston@srhuston.net> |
---|---|
date | Wed, 24 Apr 2013 11:40:27 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
83:c4dccb49471b | 84:fe021064d723 |
---|---|
1 #!/bin/sh | |
2 | |
3 HGTMP="" | |
4 cleanup_exit() { | |
5 rm -rf "$HGTMP" | |
6 } | |
7 | |
8 # Remove temporary files even if we get interrupted | |
9 trap "cleanup_exit" 0 # normal exit | |
10 trap "exit 255" HUP INT QUIT ABRT TERM | |
11 | |
12 HGTMP=$(mktemp -d ${TMPDIR-/tmp}/hgeditor.XXXXXX) | |
13 [ x$HGTMP != x -a -d $HGTMP ] || { | |
14 echo "Could not create temporary directory! Exiting." 1>&2 | |
15 exit 1 | |
16 } | |
17 | |
18 ( | |
19 grep '^HG: changed' "$1" | cut -b 13- | while read changed; do | |
20 "$HG" diff "$changed" >> "$HGTMP/diff" | |
21 done | |
22 ) | |
23 | |
24 cat "$1" > "$HGTMP/msg" | |
25 | |
26 MD5=$(which md5sum 2>/dev/null) || \ | |
27 MD5=$(which md5 2>/dev/null) | |
28 [ -x "${MD5}" ] && CHECKSUM=`${MD5} "$HGTMP/msg"` | |
29 if [ -s "$HGTMP/diff" ]; then | |
30 vim "+e $HGTMP/diff" '+set buftype=help filetype=diff' "+split $HGTMP/msg" "+wincmd r" "+resize 10" || exit $? | |
31 else | |
32 vim "$HGTMP/msg" || exit $? | |
33 fi | |
34 [ -x "${MD5}" ] && (echo "$CHECKSUM" | ${MD5} -c >/dev/null 2>&1 && exit 13) | |
35 | |
36 mv "$HGTMP/msg" "$1" | |
37 | |
38 exit $? |