summaryrefslogtreecommitdiff
path: root/emacsterm.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 /emacsterm.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 'emacsterm.sh.in')
-rw-r--r--emacsterm.sh.in48
1 files changed, 21 insertions, 27 deletions
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 <lukeshu@sbcglobal.net>
+# Copyright (C) 2011, 2013-2014, 2016 Luke Shumaker <lukeshu@sbcglobal.net>
#
# 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
}