#!/usr/bin/env zsh
+# Usage: list [[!]tag-expr ...]
+# List all issues. If tag-expr is specified, then include issues only
+# with at least one tag satisfying tag-expr. tag-expr is an expression
+# tag is compared with. If "!" is prepended to tag-expr, then it excludes
+# issues.
root=$0:h:a
. $root/lib.zsh.rc
tagsOur=($@)
-for issue (issues/**/created) {
- issue=$issue:h
- issue=${issue#issues/}
-
- tagsTheir=(`$root/tag-list $issue`)
- tagsFound=0
+tagsSatisfied() {
+ local tagsTheir=($@)
+ for our ($tagsOur) {
+ [[ ${our[1]} = "!" ]] || continue
+ for their ($tagsTheir) {
+ if [[ $their =~ ${our[2,-1]} ]]; then
+ return 1
+ fi
+ }
+ }
for our ($tagsOur) {
+ [[ ${our[1]} != "!" ]] || continue
+ local satisfied=0
for their ($tagsTheir) {
- if [[ $their =~ $our ]] ; then
- tagsFound=$(( $tagsFound + 1 ))
+ if [[ $their =~ $our ]]; then
+ satisfied=1
break
fi
}
+ [[ $satisfied -eq 1 ]] || return 1
}
- [[ $tagsFound -eq ${#tagsOur} ]] || continue
+}
+
+for issue (issues/**/created) {
+ issue=$issue:h
+ issue=${issue#issues/}
+
+ tagsTheir=(`$root/tag-list $issue`)
+ tagsSatisfied $tagsTheir || continue
print -n `cat issues/$issue/created`\\t$issue\\t
print $tagsTheir