summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Pokorný <jpokorny@redhat.com>2013-08-15 19:08:42 +0200
committerJan Pokorný <jpokorny@redhat.com>2013-08-15 19:08:42 +0200
commite28ab8bd9bd35fbd98f75116bf8f26d44b33b160 (patch)
tree927b09e73dc623e4ded3340b23b35c85237d5e2f
parenta8b8f15d9aa3a9b311c7618e90b0b10234d78bc6 (diff)
downloadwatch-bz-e28ab8bd9bd35fbd98f75116bf8f26d44b33b160.tar.gz
watch-bz-e28ab8bd9bd35fbd98f75116bf8f26d44b33b160.tar.xz
watch-bz-e28ab8bd9bd35fbd98f75116bf8f26d44b33b160.zip
Add -m/--mine option: when authenticated, show my assigned bugs
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
-rwxr-xr-xwatch-bz48
1 files 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 |\" \