From 8c67cad1f2bbcaabe23586643d670ba08f3d2a05 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 8 Jun 2016 22:30:19 -0400 Subject: Clean up. Mostly have error handling be a mode. You probably want to ignore whitespace change when viewing this diff. --- ediff.sh.in | 66 ++++++++++++++++++++++++++++--------------------------------- 1 file changed, 30 insertions(+), 36 deletions(-) (limited to 'ediff.sh.in') 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 +# Copyright (C) 2014, 2016 Luke Shumaker # # 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 "$@" -- cgit v1.2.3