]> git.plutz.net Git - serve0/commitdiff
implemented full multi file tagging
authorPaul Hänsch <paul@plutz.net>
Sat, 14 Jul 2018 13:06:10 +0000 (15:06 +0200)
committerPaul Hänsch <paul@plutz.net>
Sat, 14 Jul 2018 13:06:10 +0000 (15:06 +0200)
multitag.sh [new file with mode: 0644]

diff --git a/multitag.sh b/multitag.sh
new file mode 100644 (file)
index 0000000..43484e6
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+for select in $(seq 1 $(POST_COUNT select)); do
+  file="$_DATA/$ITEM/$(POST select $select)"
+  meta="${file%/*}/.index/meta"
+  fn="${file##*/}"
+
+  while ! mkdir "${meta}.lock"; do
+    sleep 1
+    ps -o pid \
+    | grep -q "$(cat "${meta}.lock/pid")" \
+    || break
+  done
+  printf '%i\n' >"${meta}.lock/pid"
+
+  grep -vF "   $fn" "$meta" >"${meta}.lock/mtmp"
+  read length width height tags comment x <<-EOF
+       $(grep -F "     $fn" "$meta")
+       EOF
+  tags="$(printf '%s' "${tags#tags=}" | tr , '\n')"
+
+  for tn in $(seq 1 $(POST_COUNT tag)); do
+    tags="$tags${BR}$(POST tag $tn |sed -r 's;\t;\\t;g; s;\r;;g;')"
+  done
+  tags="$tags${BR}$(POST newtag |sed -r 's;\t;\\t;g;')"
+
+  printf '%s\t%s\t%s\ttags=%s\t%s\t%s\n' \
+         "$length" "$width" "$height" \
+         "$(printf %s "$tags" |sort -u |tr '\n' ,)" \
+         "$comment" "$fn" \
+  >>"${meta}.lock/mtmp"
+  mv "${meta}.lock/mtmp" "$meta"
+
+  rm "${meta}.lock/pid"; rmdir "${meta}.lock"
+done