From 607199cc67f143387d34e43851b9031082dfd29c Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 30 Aug 2017 17:50:10 +0200 Subject: use getopt --- dic | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/dic b/dic index fb81251..8588998 100755 --- a/dic +++ b/dic @@ -1,19 +1,26 @@ #! /bin/sh -# usage: dic WORD [LANG] +# usage: dic [--lang=LANG] WORD... # where LANG may be one of en, fr, es, it, ch, ru, pt, pl # multiple WORDs may be seperated by + like this: multiple+words set -euf main() { - case $# in - 1|2) :;; # ok - *) usage; exit 23;; - esac - - search=$1 - lang=de - lp=${2-en}de + _args=$(getopt -n "$0" -s sh \ + -o l: \ + -l lang: \ + -- "$@") + if \test $? != 0; then exit 1; fi + eval set -- "$_args" + unset _args + lang=en + while :; do case $1 in + -l|--lang) lang=$2; shift 2;; + --) shift; break;; + esac; done + + search=$* + lp=${lang}de GET | simplify | tac } -- cgit v1.2.3