ambevar-dotfiles/.emacs.d/snippets/sh-mode/getopt

43 lines
561 B
Plaintext

# name: getopt
# key: getopt
# --
_printhelp ()
{
cat<<EOF
Usage: \${1##*/} [-h]
Synopsis.
-h: Show this help.
EOF
}
USE_OPT=0
while getopts ":dh" opt; do
case \$opt in
h)
_printhelp "\$0"
return 1
;;
d)
USE_OPT=1
;;
?)
_printhelp "\$0"
return 1
;;
:)
_printhelp "\$0"
return 1
;;
esac
done
shift \$((\$OPTIND - 1))
if [ \$# -eq 0 ]; then
_printhelp "\$0"
return 1
fi