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. --- emacsterm.sh.in | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) (limited to 'emacsterm.sh.in') diff --git a/emacsterm.sh.in b/emacsterm.sh.in index 3340bea..6ecbed3 100644 --- a/emacsterm.sh.in +++ b/emacsterm.sh.in @@ -1,6 +1,6 @@ #!@bash@ -# Copyright (C) 2011, 2013-2014 Luke Shumaker +# Copyright (C) 2011, 2013-2014, 2016 Luke Shumaker # # This file is not considered part of GNU Emacs. # @@ -33,13 +33,15 @@ usage() { main() { + declare mode declare mimic declare cmd declare -a flags parse "$@" - emacsclient "${flags[@]}" --eval \ - "(term $(emacs_quote "${cmd}"))" + next \ + emacsclient "${flags[@]}" --eval \ + "(term $(emacs_quote "${cmd}"))" } # Sets the 'global' variables: @@ -48,15 +50,14 @@ main() { # - cmd # - flags (array) parse() { + mode=normal mimic=rxvt cmd= flags=() - - local mode=normal - local error=false + emacs_getopt_init - while [[ $# -gt 0 ]]; do + while [[ $# -gt 0 ]] && [ "$mode" != error ]; do case "$1" in -V|--version) shift; mode=version;; -H|--help) shift; mode=usage;; @@ -69,25 +70,18 @@ parse() { esac done - if $error; then - usage >&2 - exit 1 - fi - case "$mode" in - usage) usage; exit 0;; - version) version; exit 0;; - esac - - if [[ -z "$cmd" ]]; then - # This matches rxvt's behavior. - # This is simpler than xterm's behavior. - cmd="${cmd:-${SHELL:-/bin/sh}}" - fi + # This matches rxvt's behavior. + # This is simpler than xterm's behavior. + cmd="${cmd:-${SHELL:-/bin/sh}}" } # Return status is the number of things to shift parse_emacs_getopt() { declare -a flag + # Because we don't want options to get combined, we run getopt + # with : stripped, so that we can check that it returned 2 + # arguments: the flag itself, and '--'. If there were + # combined flags, then it will return more than 2 arguments. if eval "flag=($(getopt -a \ -n "$0" \ -o "${emacs_getopt_o//:/}" \ @@ -103,12 +97,12 @@ parse_emacs_getopt() { return 2 else # Missing the required 2nd part - getopt -a \ + getopt -Q -a \ -n "$0" \ -o "$emacs_getopt_o" \ -l "$emacs_getopt_l" \ - -- "$flag" >/dev/null - error=true + -- "$flag" + mode=error return 1 fi else @@ -119,8 +113,8 @@ parse_emacs_getopt() { else # getopt either didn't work, or did combined flags # Have getopt display its own error message: - getopt -a -n "$0" -o '' -l '' -- "$1" >/dev/null - error=true + getopt -Q -a -n "$0" -o '' -l '' -- "$1" + mode=error return 1 fi } @@ -153,7 +147,7 @@ parse_shell() { else shift error "extra arguments: %s" "$*" - error=true + mode=error fi } -- cgit v1.2.3