- file="$_DATA/$ITEM/$(POST select $select)"
- meta="${file%/*}/.index/meta"
-
- fn="$(meta_name "$file")"
- read -r length width height tags comment discard <<-EOF
- $(meta_info "$file")
- EOF
- [ "${length%%[1-9]*}" -o "${width%%[1-9]*}" -o "${height%%[1-9]*}" = 0 ] \
- && read -r length width height discard <<-EOF
- $(meta_line "$file"; echo Rereading meta for "$file" >&2)
- EOF
- [ "${tags%%tags=*}" ] && tags='tags=';
- [ "${comment%%comment=*}" ] && comment='comment='
-
- if LOCK "$meta"; then
- grep -avF " $fn" "$meta" >"${meta}.tmp"
-
- tags="$(UNSTRING "${tags#tags=}" |tr , '\n')"
-
- for tn in $(seq 1 $(POST_COUNT tag)); do
- tags="$(printf '%s\n%s' "$tags" "$(POST tag $tn)")"
+ file="$(POST select $select)"
+ read_meta "${file%.*}" || continue
+
+ tags="$(printf %s\\n "$META_TAGS" |tr , \\n)"
+
+ if [ "$op" = add ]; 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="${tags}${BR}${newtags}"
+
+ elif [ "$op" = del ]; then
+ detag="${newtags}${BR}"; while [ "$detag" ]; do
+ tags="$(printf '%s\n' "$tags" |grep -vxFe "${detag%%${BR}*}")"
+ detag="${detag#*${BR}}"
+ done
+
+ elif [ "$op" = flip ]; then
+ fliptag="${newtags}${BR}"; while [ "$fliptag" ]; do
+ comp="$tags"
+ tags="$(printf '%s\n' "$tags" |grep -vxFe "${fliptag%%${BR}*}")"
+ [ "$comp" = "$tags" ] && tags="${tags}${BR}${fliptag%%${BR}*}"
+ fliptag="${fliptag#*${BR}}"