]> git.plutz.net Git - serve0/blob - multitag.sh
bugfix: assign new tags from text field
[serve0] / multitag.sh
1 #!/bin/sh
2
3 . "$_EXEC/db_meta.sh"
4
5 newtags=''
6 for tn in $(seq 1 $(POST_COUNT tag)); do
7   newtags="$(POST tag $tn)${BR}${newtags}"
8 done
9 newtags="$(POST newtagn |tr -d '\r' |tr , '\n')${BR}${newtags}"
10
11 while [ "${newtags#${BR}}" != "${newtags}" ]; do newtags="${newtags#${BR}}"; done
12 while [ "${newtags%${BR}}" != "${newtags}" ]; do newtags="${newtags%${BR}}"; done
13
14 [ "$(POST op)" = del ] && deltags="$newtags"
15
16 for select in $(seq 1 $(POST_COUNT select)); do
17   file="$(POST select $select)"
18
19   read_meta "${file%.*}" || continue
20   tags="$(printf %s\\n "$META_TAGS" |tr , \\n)"
21
22   if [ ! "$deltags" ]; then
23     extags="$(printf '%s' "${newtags}" |grep -e "^-" |cut -d: -f1 )"
24     [ "$extags" ] && tags="$(printf %s\\n "$tags" |grep -vwFe "$extags")"
25     if printf %s "${newtags}" |grep -e "^-" |grep -qEe "^-[^:]+$"; then
26       tags="$(printf %s\\n "$tags" |grep -vEe '^-[^:]+$')"
27     fi
28     tags="$(printf '%s\n' "${tags},${newtags}" \
29             | tr , '\n' |sort -u |tr '\n' ,)"
30   else
31     detag="${deltags}${BR}"; while [ "$detag" ]; do
32       tags="$(printf '%s\n' "$tags" |grep -vxFe "${detag%%${BR}*}")"
33       detag="${detag#*${BR}}"
34     done
35     tags="$(printf '%s\n' "$tags" |sort -u |tr '\n' ,)"
36   fi
37   tags="${tags#,}"; tags="${tags%,}"
38
39   update_meta "$META_NAME" tags="${tags}"
40 done