From e28ab8bd9bd35fbd98f75116bf8f26d44b33b160 Mon Sep 17 00:00:00 2001 From: Jan Pokorný Date: Thu, 15 Aug 2013 19:08:42 +0200 Subject: Add -m/--mine option: when authenticated, show my assigned bugs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Pokorný --- watch-bz | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/watch-bz b/watch-bz index a7c177c..9a63501 100755 --- a/watch-bz +++ b/watch-bz @@ -38,6 +38,8 @@ STATUS=OPEN REFRESH_INTERVAL=600 # [s], better not to drain bugzilla's power... BZUSER= BZPASSWORD= +MINE=0 +QUERY_REST= # user configuration [ -f ~/.watchbzrc ] && source ~/.watchbzrc @@ -72,14 +74,40 @@ fi SEP=@@@ WIDTH=$(( $(stty size | cut -d' ' -f2) - 1 )) -# arguments -if [ $# -ge 1 ]; then - if [[ "$1" = -* ]]; then - STATUS=$(echo "$1" | cut -c2-) - shift - fi - if [ $# -ge 1 ]; then - COMPONENT="$1" +# options/arguments + +CMDLINE_COMPONENT= +CMDLINE_STATUS= +CMDLINE_HELP= +CMDLINE_QUERY_REST= +while [ $# -ge 1 ]; do + case "$1" in + -h|--help) + read -p "wanna see the script (the only help ATM)? [Yn] " \ + CMDLINE_HELP + [[ ${CMDLINE_HELP} =~ ^[Yy].*|^$ ]] && less "${BASH_SOURCE}"; exit;; + -m|--mine) MINE=1;; + --) shift; break;; + -*) CMDLINE_STATUS+=",$(echo "$1" | cut -c2-)";; + *) CMDLINE_COMPONENT+=",$1";; + esac + shift +done +while [ $# -ge 1 ]; do CMDLINE_QUERY_REST+=" $1"; shift; done + +# normalize and check + +die () { echo "$@"; exit 2;} + +test -n "${CMDLINE_COMPONENT}" && COMPONENT=${CMDLINE_COMPONENT#,} +test -n "${CMDLINE_STATUS}" && STATUS=${CMDLINE_STATUS#,} +test -n "${CMDLINE_QUERY_REST}" && QUERY_REST=${CMDLINE_QUERY_REST} + +if test -z "${MINE}" || test "${MINE}" -eq 0; then :; else + if test -n "${BZUSER}"; then + QUERY_REST="-a \"${BZUSER}\" ${QUERY_REST}" + else + die "BZUSER has to be defined to use --mine" fi fi @@ -157,8 +185,8 @@ do_watch () { TAIL="${HERE}/table-data $SEP | sort | ${PRECOLORIZE} | cut -c-$WIDTH | ${COLORIZE}" [ "${WATCHBZ_DEBUG}" -ne 0 ] && TAIL="cat" ${EXEC} \ - "$BUGZILLA --cookiefile="${BUGZILLA_COOKIE}" query -c $COMPONENT \ - -t $STATUS --outputformat $OUTPUT_FMT \ + "${BUGZILLA} --cookiefile=${BUGZILLA_COOKIE} query -c ${COMPONENT} \ + -t \"${STATUS}\" --outputformat ${OUTPUT_FMT} ${QUERY_REST} \ | sed -u \ -e \"s|${SEP}Red Hat Enterprise Linux |${SEP}EL|\" \ -e \"s|${SEP}Fedora|${SEP} F |\" \ -- cgit