Emacs: improved sh-while-getopts

master
Pierre Neidhardt 2014-02-13 18:55:06 +01:00
parent e3dee12875
commit a047cda145
1 changed files with 26 additions and 24 deletions

View File

@ -54,10 +54,12 @@ otherwise use 'sh-shell-file'."
} }
") ")
(define-skeleton sh-getopts
(define-skeleton sh-while-getopts
"Insert a getops prototype." "Insert a getops prototype."
nil "optstring: "
"_printhelp () > "_printhelp ()
{ {
cat<<EOF cat<<EOF
Usage: ${1##*/} [OPTIONS] FILES Usage: ${1##*/} [OPTIONS] FILES
@ -67,29 +69,29 @@ Options:
-h: Show this help. -h: Show this help.
EOF EOF
} }" \n
\n
opt_test=false > "while getopts :" str " OPT; do" \n
while getopts ':ht' opt; do > "case $OPT in" \n
case $opt in '(setq v1 (append (vconcat str) nil))
h) ( (prog1 (if v1 (char-to-string (car v1)))
_printhelp \"$0\" (if (eq (nth 1 v1) ?:)
exit 1 ;; (setq v1 (nthcdr 2 v1)
t) v2 "\"$OPTARG\"")
opt_test=true ;; (setq v1 (cdr v1)
?) v2 nil)))
_printhelp \"$0\" > str ")" \n
exit 1 ;; > _ v2 " ;;" \n)
esac > "?)" \n
done > "_printhelp \"$0\"" \n
"exit 1 ;;" > \n
shift $(($OPTIND - 1)) "esac" > \n
"done" > \n\n
if [ $# -eq 0 ]; then "shift $(($OPTIND - 1))" \n
"if [ $# -eq 0 ]; then
_printhelp \"$0\" _printhelp \"$0\"
exit 1 exit 1
fi fi" \n)
")
(define-skeleton sh-command (define-skeleton sh-command
"Insert a line that executes if command is found in path." "Insert a line that executes if command is found in path."