]> git.plutz.net Git - serve0/blobdiff - list.sh
fully implemented listing by filter
[serve0] / list.sh
diff --git a/list.sh b/list.sh
index 607ea201ed6580ef2a0d5087c72860600669708c..72b4fc3561d427731d20b847341036a280c276cd 100644 (file)
--- 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}".*)"
@@ -69,7 +88,7 @@ list_items() {
   if   [ "$mode" = browse -a "$ORDER" = Date ]; then
     list_directories
     list_filemeta . |cut -f2- \
-    | xargs -d\n stat -c '%Y   %n' \
+    | xargs -rd'\n' stat -c '%Y        %n' \
     | sort -rn |cut -d/ -f2-
   elif [ "$mode" = browse -a "$ORDER" = Name ]; then
     list_directories
@@ -77,7 +96,7 @@ list_items() {
     | sort -k 2 |cut -d/ -f2-
   elif [ "$mode" = index  -a "$ORDER" = Date ]; then
     list_index |cut -f2- \
-    | xargs -d'\n' stat -c '%Y %n' \
+    | xargs -rd'\n' stat -c '%Y        %n' \
     | sort -rn | cut -d/ -f2-
   elif [ "$mode" = index  -a "$ORDER" = Name ]; then
     list_index | sort -k 2 | cut -d/ -f2-