]> git.plutz.net Git - serve0/blobdiff - multitag.sh
allow tag removal in multitagger
[serve0] / multitag.sh
index 45798069f237adfab581e7bcbe7b9034de3168d2..8b60adebb1ac8e265866f00570c47d124c0ca9e3 100644 (file)
@@ -7,7 +7,8 @@ newtags=''
 for tn in $(seq 1 $(POST_COUNT tag)); do
   newtags="${newtags},$(POST tag $tn)"
 done
-newtags="${newtags},$(POST newtag |tr -d '\r')"
+newtags="${newtags},$(POST newtag |tr -d '\r' |tr '\n' ,)"
+[ "$(POST op)" = del ] && deltags="$newtags"
 
 for select in $(seq 1 $(POST_COUNT select)); do
   file="$_DATA/$ITEM/$(POST select $select |PATH)"
@@ -16,9 +17,19 @@ 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
+    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#*,}"
+    done
+    tags="$(printf '%s\n' "$tags" |sort -u |tr '\n' , |STRING)"
+  fi
   tags="${tags#,}"; tags="${tags%,}"
 
   if LOCK "$meta"; then