]> git.plutz.net Git - serve0/blobdiff - multitag.sh
altered groupmatch algorithm
[serve0] / multitag.sh
index 45798069f237adfab581e7bcbe7b9034de3168d2..353ead6dbf838d331d25c45a24ce41a2a34d181c 100644 (file)
@@ -5,9 +5,14 @@
 
 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')"
+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
   file="$_DATA/$ITEM/$(POST select $select |PATH)"
@@ -16,9 +21,24 @@ for select in $(seq 1 $(POST_COUNT select)); do
   read -r length width height tags comment fn <<-EOF
        $(meta_info "$file")
        EOF
-
-  tags="$(UNSTRING "${tags#tags=}")"
-  tags="$(printf '%s\n' "${tags}" "${newtags}" |tr , '\n' |sort -u |tr '\n' , |STRING)"
+  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}${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
   tags="${tags#,}"; tags="${tags%,}"
 
   if LOCK "$meta"; then