]> Sergey Matveev's repositories - schwabrak.git/blobdiff - list
!-tags
[schwabrak.git] / list
diff --git a/list b/list
index 4e7fa51b0df11395a2cdabab3029beb011c89df98720b384699200ad84314c53..16416757278cfea94b24529cb7ae4ccc98b21df95412badf48085151a5d254ab 100755 (executable)
--- a/list
+++ b/list
@@ -1,25 +1,44 @@
 #!/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