hgeditor
56 lines
| 1.2 KiB
| text/plain
|
TextLexer
|
r544 | #!/bin/sh | ||
|
r186 | # | ||
|
r1599 | # This is an example of using HGEDITOR to create of diff to review the | ||
# changes while commiting. | ||||
|
r684 | |||
|
r666 | # If you want to pass your favourite editor some other parameters | ||
# only for Mercurial, modify this: | ||||
|
r796 | case "${EDITOR}" in | ||
"") | ||||
EDITOR="vi" | ||||
;; | ||||
|
r348 | emacs) | ||
EDITOR="$EDITOR -nw" | ||||
;; | ||||
gvim|vim) | ||||
EDITOR="$EDITOR -f -o" | ||||
;; | ||||
esac | ||||
|
r796 | |||
HGTMP="" | ||||
cleanup_exit() { | ||||
rm -rf "$HGTMP" | ||||
} | ||||
|
r754 | # Remove temporary files even if we get interrupted | ||
|
r831 | trap "cleanup_exit" 0 # normal exit | ||
trap "exit 255" 1 2 3 6 15 # HUP INT QUIT ABRT TERM | ||||
|
r796 | |||
HGTMP="${TMPDIR-/tmp}/hgeditor.$RANDOM.$RANDOM.$RANDOM.$$" | ||||
(umask 077 && mkdir "$HGTMP") || { | ||||
echo "Could not create temporary directory! Exiting." 1>&2 | ||||
exit 1 | ||||
} | ||||
|
r754 | ( | ||
grep '^HG: changed' "$1" | cut -b 13- | while read changed; do | ||||
|
r4687 | "$HG" diff "$changed" >> "$HGTMP/diff" | ||
|
r754 | done | ||
) | ||||
|
r348 | |||
|
r1599 | cat "$1" > "$HGTMP/msg" | ||
|
r684 | |||
|
r3025 | MD5=$(which md5sum 2>/dev/null) || \ | ||
|
r4659 | MD5=$(which md5 2>/dev/null) | ||
|
r3025 | [ -x "${MD5}" ] && CHECKSUM=`${MD5} "$HGTMP/msg"` | ||
|
r1009 | if [ -s "$HGTMP/diff" ]; then | ||
$EDITOR "$HGTMP/msg" "$HGTMP/diff" || exit $? | ||||
else | ||||
$EDITOR "$HGTMP/msg" || exit $? | ||||
fi | ||||
|
r3025 | [ -x "${MD5}" ] && (echo "$CHECKSUM" | ${MD5} -c >/dev/null 2>&1 && exit 13) | ||
|
r754 | |||
|
r1599 | mv "$HGTMP/msg" "$1" | ||
|
r348 | |||
|
r831 | exit $? | ||