From 8660fbcbf6a928e2d2fd0243258fb030fa8ab55a Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Tue, 15 Jul 2008 21:50:24 +0200 Subject: [PATCH] Enhanced `todo` by using `getopt` --- todo.sh | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/todo.sh b/todo.sh index 6f1f03a..b191bee 100755 --- a/todo.sh +++ b/todo.sh @@ -38,19 +38,23 @@ todo_trap() trap ':' INT -while [ $# -gt 0 ]; do +options=$( getopt -o "$t:" -- "$@" ) +if [ $? -ne 0 ]; then + todo_usage +fi + +# load new arguments list +eval set -- "$options" + +while [ $# -gt 0 ]; do case "$1" in - -t) if [ -n "$2" ]; then - TAGS="$TAGS $2" - shift 2 - else - todo_usage missing value - fi ;; + -t) TAGS="$TAGS $2"; shift ;; + + --) shift; break ;; -*) todo_usage unknown option "$1" ;; - *) break - ;; esac + shift done TAGS=$( echo "$TAGS" | tr 'a-z' 'A-Z' ) -- 2.11.4.GIT