]> git.plutz.net Git - serve0/blobdiff - multitag.sh
altered groupmatch algorithm
[serve0] / multitag.sh
index 8b60adebb1ac8e265866f00570c47d124c0ca9e3..353ead6dbf838d331d25c45a24ce41a2a34d181c 100644 (file)
@@ -5,9 +5,13 @@
 
 newtags=''
 for tn in $(seq 1 $(POST_COUNT tag)); do
-  newtags="${newtags},$(POST tag $tn)"
+  newtags="$(POST tag $tn)${BR}${newtags}"
 done
-newtags="${newtags},$(POST newtag |tr -d '\r' |tr '\n' ,)"
+newtags="$(POST newtag |tr -d '\r' |tr , '\n')${BR}${newtags}"
+
+while [ "${newtags#${BR}}" != "${newtags}" ]; do newtags="${newtags#${BR}}"; done
+while [ "${newtags%${BR}}" != "${newtags}" ]; do newtags="${newtags%${BR}}"; done
+
 [ "$(POST op)" = del ] && deltags="$newtags"
 
 for select in $(seq 1 $(POST_COUNT select)); do
@@ -20,13 +24,18 @@ for select in $(seq 1 $(POST_COUNT select)); do
   tags="$(UNSTRING "${tags#tags=}" |tr , '\n')"
 
   if [ ! "$deltags" ]; then
+    extags="$(printf '%s' "${newtags}" |grep -e "^-" |cut -d: -f1 )"
+    [ "$extags" ] && tags="$(printf %s\\n "$tags" |grep -vwFe "$extags")"
+    if printf %s "${newtags}" |grep -e "^-" |grep -qEe "^-[^:]+$"; then
+      tags="$(printf %s\\n "$tags" |grep -vEe '^-[^:]+$')"
+    fi
     tags="$(printf '%s\n' "${tags},${newtags}" \
             | tr , '\n' |sort -u |tr '\n' , \
             | STRING)"
   else
-    detag="${deltags},"; while [ "$detag" ]; do
-      tags="$(printf '%s\n' "$tags" |grep -vxFe "${detag%%,*}")"
-      detag="${detag#*,}"
+    detag="${deltags}${BR}"; while [ "$detag" ]; do
+      tags="$(printf '%s\n' "$tags" |grep -vxFe "${detag%%${BR}*}")"
+      detag="${detag#*${BR}}"
     done
     tags="$(printf '%s\n' "$tags" |sort -u |tr '\n' , |STRING)"
   fi