diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-11-02 23:00:59 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-11-02 23:00:59 -0400 |
commit | b80d5009b0434bf2518027b62cd4cecc86fe7b1a (patch) | |
tree | e4005df7d195e7c63b79358d40826fd94f69834b | |
parent | feb92a5e5e06964c03038b9843376f48cea55ce6 (diff) |
emacsterm: add real option handling
-rw-r--r-- | emacsterm.sh | 74 |
1 files changed, 59 insertions, 15 deletions
diff --git a/emacsterm.sh b/emacsterm.sh index ac3e186..e83270d 100644 --- a/emacsterm.sh +++ b/emacsterm.sh @@ -1,19 +1,63 @@ -#!/bin/sh -# emacs-xterm-handler +#!/bin/bash -cmd=${SHELL?/bin/sh} -set -- $(getopt -n $0 -o e -- "$@") -if [ $? -ne 0 ]; then - echo "Usage $0 [-e CMD]" >> /dev/stderr -fi +mimic=rxvt -for o do - case "$o" in - -e) shift; cmd=$1; shift;; - esac -done +usage() { + echo "Usage $0 [OPTIONS]" + echo + echo 'Options:' + echo ' -r Use rxvt-style parsing of CMD for -e (execve)' + echo ' -x Use xterm-style parsing of CMD for -e (system)' + echo ' -e CMD Execute CMD instead of ${SHELL:-/bin/sh}' + echo ' -h Show this message' +} -elisp_expr="(emacs-terminal-emulator \"$cmd\")" +cmd=${SHELL:-/bin/sh} +usage=false +error=false +while getopts 'rxe:h' flag; do + case "$flag" in + r) mimic=rxvt;; + x) mimic=xterm;; + e) + if [[ $cmd == "${SHELL:-/bin/sh}" ]]; then + cmd="$(mktemp -t "${0##*/}.XXXXXXXXXX")" + trap "rm -f '$cmd'" EXIT + { + echo '#!/bin/bash' + case "$mimic" in + xterm) + printf "sh -c %q\n" "$OPTARG" + ;; + rxvt) + shift $(($OPTIND - 1)) + printf '%q ' "$OPTARG" "$@" + echo + ;; + esac + } > "$cmd" + chmod 755 "$cmd" + else + echo "$0: option -e may only be given once" >>/dev/stderr + error=true + fi + ;; + h) usage=true;; + *) error=true;; + esac +done +shift $(($OPTIND - 1)) +if [[ $# != 0 ]]; then + echo "$0: extra arguments: $*" >>/dev/stderr + error=true +fi +if $error; then + usage >>/dev/stderr + exit 1 +fi +if $usage; then + usage + exit 0 +fi -emacsclient -a "" -c -n --eval "$elisp_expr" \ - '(set-window-dedicated-p (selected-window) t)' +emacsclient -a "" -c --eval "(ansi-term \"${cmd}\")" '(set-window-dedicated-p (selected-window) t)' |