diff --git a/.emacs.d/mode-shell.el b/.emacs.d/mode-shell.el index bff4f1cd..91c24f18 100644 --- a/.emacs.d/mode-shell.el +++ b/.emacs.d/mode-shell.el @@ -54,10 +54,12 @@ otherwise use 'sh-shell-file'." } ") -(define-skeleton sh-getopts + + +(define-skeleton sh-while-getopts "Insert a getops prototype." - nil - "_printhelp () + "optstring: " + > "_printhelp () { cat< "while getopts :" str " OPT; do" \n +> "case $OPT in" \n +'(setq v1 (append (vconcat str) nil)) +( (prog1 (if v1 (char-to-string (car v1))) + (if (eq (nth 1 v1) ?:) + (setq v1 (nthcdr 2 v1) + v2 "\"$OPTARG\"") + (setq v1 (cdr v1) + v2 nil))) + > str ")" \n + > _ v2 " ;;" \n) +> "?)" \n +> "_printhelp \"$0\"" \n +"exit 1 ;;" > \n +"esac" > \n +"done" > \n\n +"shift $(($OPTIND - 1))" \n +"if [ $# -eq 0 ]; then _printhelp \"$0\" exit 1 -fi -") +fi" \n) (define-skeleton sh-command "Insert a line that executes if command is found in path."