X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;f=multitag.sh;h=353ead6dbf838d331d25c45a24ce41a2a34d181c;hb=608e267413cf7f8399cacbbfc4269d3c3820a3aa;hp=45798069f237adfab581e7bcbe7b9034de3168d2;hpb=1b79a90402ee3fe450575085470b3ec6d084d78b;p=serve0 diff --git a/multitag.sh b/multitag.sh index 4579806..353ead6 100644 --- a/multitag.sh +++ b/multitag.sh @@ -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