From: Paul Hänsch Date: Mon, 16 Jul 2018 12:34:54 +0000 (+0200) Subject: fully implemented listing by filter X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=7c5e13183df4717e76f84a5cf99daa6d2d51d91b;p=serve0 fully implemented listing by filter --- diff --git a/list.sh b/list.sh index 52b78b2..72b4fc3 100644 --- a/list.sh +++ b/list.sh @@ -34,14 +34,33 @@ list_directories(){ ) | cut -d/ -f2- | sort } +[ "$FILTER" ] && list_fex="$( + fex='p' + STRING "$FILTER^" \ + | sed -r 's;\^;\n;g; s;[]\/\(\)\\\^\$\?\.\+\*\;\[\{\}];\\&;g' \ + | while read -r f; do + [ ! "${f#~}" ] && continue + [ "${f#~}" = "$f" ] \ + && fex="/(\ttags=([^\t]*,)?)(${f})((,[^\t]*)?\t)/{${fex}}" \ + || fex="/(\ttags=([^\t]*,)?)(${f#~})((,[^\t]*)?\t)/d; ${fex}" + printf '%s\n' "${fex}" + done \ + | tail -n1 +)" + list_filemeta(){ local meta base f fn file base="$1" meta="$1/.index/meta" meta_dir "$_DATA/$ITEM/$base" - grep -iE "$(STRING "${SEARCH}")" "$_DATA/$ITEM/$meta" \ - | cut -f1,6- \ + if [ "$FILTER" ]; then + sed -nr "$list_fex" "$_DATA/$ITEM/$meta" + elif [ "${SEARCH#!}" != "${SEARCH}" ]; then + grep -viE "$(STRING "${SEARCH#!}")" "$_DATA/$ITEM/$meta" + else + grep -iE "$(STRING "${SEARCH}")" "$_DATA/$ITEM/$meta" + fi |cut -f1,6- \ | while f="$(line)"; do fn="$(UNSTRING "${f#* }")"; fn="${fn%${CR}}"; file="$(printf '%s\n' "$_DATA/$ITEM/$base/${fn}".*)"