summaryrefslogtreecommitdiff
path: root/ediff.sh.in
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-06-08 22:30:19 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-06-08 23:03:05 -0400
commit8c67cad1f2bbcaabe23586643d670ba08f3d2a05 (patch)
tree812d0cba8c0d157d8c22b67093c8f6c8a3bcd099 /ediff.sh.in
parent482ff021e313131af25eb6c8d70bd4d414c32105 (diff)
Clean up. Mostly have error handling be a mode.
You probably want to ignore whitespace change when viewing this diff.
Diffstat (limited to 'ediff.sh.in')
-rw-r--r--ediff.sh.in66
1 files changed, 30 insertions, 36 deletions
diff --git a/ediff.sh.in b/ediff.sh.in
index 164e6da..569721e 100644
--- a/ediff.sh.in
+++ b/ediff.sh.in
@@ -1,6 +1,6 @@
#!@bash@
-# Copyright (C) 2014 Luke Shumaker <lukeshu@sbcglobal.net>
+# Copyright (C) 2014, 2016 Luke Shumaker <lukeshu@sbcglobal.net>
#
# This file is not considered part of GNU Emacs.
#
@@ -21,7 +21,7 @@ m4_include(common.sh.in)
usage() {
print 'Usage: %q [OPTIONS] FILE_A FILE_B' "$0"
- print 'Usage: %q -3 [OPTIONS] FILE_A FILE_B FILE_C' "$0"
+ print ' or: %q -3 [OPTIONS] FILE_A FILE_B FILE_C' "$0"
print "Use Emacs' ediff-mode to compare two files"
echo
print 'The following OPTIONS are accepted:'
@@ -34,46 +34,40 @@ main() {
declare -a flags=()
declare -a files=()
declare -i cnt=2
- declare error=false
- declare mode=normal
declare cmd=ediff
+ declare mode=normal
emacs_getopt_init
declare args
- args="$(emacs_getopt 3r recursive "$@")" || error=true
- eval set -- "$args"
- while true; do
- case "$1" in
- -V|--version) shift; mode=version;;
- -H|--help) shift; mode=usage;;
- -r|--recursive) shift; cmd=edirs;;
- -3) shift; cnt=3;;
- --) shift; break;;
- *)
- if [[ $1 =~ $emacs_getopt_2 ]]; then
- flags+=("$1" "$2"); shift 2
- else
- flags+=("$1"); shift 1
- fi
- ;;
- esac
- done
- files=("$@")
- if [[ $mode == normal ]]; then
- [[ ${#files[@]} = ${cnt} ]] || error=true
- fi
-
- if $error; then
- usage >&2
- return 1
+ if ! args="$(emacs_getopt 3r recursive "$@")"; then
+ mode=error
+ else
+ eval set -- "$args"
+ while true; do
+ case "$1" in
+ -V|--version) shift; mode=version;;
+ -H|--help) shift; mode=usage;;
+ -r|--recursive) shift; cmd=edirs;;
+ -3) shift; cnt=3;;
+ --) shift; break;;
+ *)
+ if [[ $1 =~ $emacs_getopt_2 ]]; then
+ flags+=("$1" "$2"); shift 2
+ else
+ flags+=("$1"); shift 1
+ fi
+ ;;
+ esac
+ done
+ files=("$@")
+ if [[ $mode == normal ]]; then
+ [[ ${#files[@]} = ${cnt} ]] || mode=error
+ fi
fi
- case "$mode" in
- usage) usage; return 0;;
- version) version; return 0;;
- esac
- emacsclient "${flags[@]}" --eval \
- "(${cmd}${cnt#2} $(emacs_quote "${files[@]}"))"
+ next "$mode" \
+ emacsclient "${flags[@]}" --eval \
+ "(${cmd}${cnt#2} $(emacs_quote "${files[@]}"))"
}
main "$@"