]> git.plutz.net Git - serve0/commitdiff
improved grouping, improved shell compatibility
authorPaul Hänsch <paul@plutz.net>
Sun, 24 May 2020 13:38:13 +0000 (15:38 +0200)
committerPaul Hänsch <paul@plutz.net>
Sun, 24 May 2020 13:38:13 +0000 (15:38 +0200)
list.sh

diff --git a/list.sh b/list.sh
index 58eb0628b99378367f230bcaf82e4797917b604d..8ba460e066388c267eb53ae16b2df95341ac04d0 100644 (file)
--- a/list.sh
+++ b/list.sh
@@ -49,12 +49,12 @@ list_item() {
 [ "$FILTER" ] && list_fex="$(
   fex='p'
   STRING "$FILTER^" \
 [ "$FILTER" ] && list_fex="$(
   fex='p'
   STRING "$FILTER^" \
-  | sed -r 's;\^;\n;g; s;[]\/\(\)\\\^\$\?\.\+\*\;\[\{\}];\\&;g' \
+  | sed -E 's;\^;\n;g; s;[]\/\(\)\\\^\$\?\.\+\*\;\[\{\}];\\&;g' \
   | while read -r f; do
   | while read -r f; do
-    [ ! "${f#~}" ] && continue
-    [ "${f#~}" = "$f" ] \
+    [ "${f#\~}" ] || continue
+    [ "${f#\~}" = "$f" ] \
     && fex="/(\ttags=([^\t]*,)?)(${f})((,[^\t]*)?\t)/{${fex}}" \
     && fex="/(\ttags=([^\t]*,)?)(${f})((,[^\t]*)?\t)/{${fex}}" \
-    || fex="/(\ttags=([^\t]*,)?)(${f#~})((,[^\t]*)?\t)/d; ${fex}"
+    || fex="/(\ttags=([^\t]*,)?)(${f#\~})((,[^\t]*)?\t)/d; ${fex}"
     printf '%s\n' "${fex}"
   done \
   | tail -n1
     printf '%s\n' "${fex}"
   done \
   | tail -n1
@@ -71,15 +71,16 @@ list_fullname(){
 
 list_filter(){
   if [ "$FILTER" ]; then
 
 list_filter(){
   if [ "$FILTER" ]; then
-    sed -nr "$list_fex"
+    printf "FEX: %s\n" "$list_fex" >&2
+    sed -nE "$list_fex"
   elif [ "${SEARCH#!}" != "${SEARCH}" ]; then
     grep -aviEe "$(STRING "${SEARCH}" \
   elif [ "${SEARCH#!}" != "${SEARCH}" ]; then
     grep -aviEe "$(STRING "${SEARCH}" \
-                 | sed -r ':x s;((^|[^\\])(\\\\)*)\+;\1 ;g; tx;
+                 | sed -E ':x s;((^|[^\\])(\\\\)*)\+;\1 ;g; tx;
                             s;((^|[^\\])(\\\\)*)\\\+;\1+;g;
                             s; ;\\+;g;')"
   elif [ "${SEARCH}" ]; then
     grep -aiEe "$(STRING "${SEARCH}" \
                             s;((^|[^\\])(\\\\)*)\\\+;\1+;g;
                             s; ;\\+;g;')"
   elif [ "${SEARCH}" ]; then
     grep -aiEe "$(STRING "${SEARCH}" \
-                 | sed -r ':x s;((^|[^\\])(\\\\)*)\+;\1 ;g; tx;
+                 | sed -E ':x s;((^|[^\\])(\\\\)*)\+;\1 ;g; tx;
                             s;((^|[^\\])(\\\\)*)\\\+;\1+;g;
                             s; ;\\+;g;')"
   else
                             s;((^|[^\\])(\\\\)*)\\\+;\1+;g;
                             s; ;\\+;g;')"
   else
@@ -95,9 +96,11 @@ list_order(){
   elif [ $ORDER = Group ]; then
     sed -E '
       :X
   elif [ $ORDER = Group ]; then
     sed -E '
       :X
-      s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^ 0-9]*)(-[0-9a-zA-Z_-]{11}\r|-ph[0-9a-f]{13}\r|-[0-9]{8}\r|[0-9]+\+?)(.*)$;\1\r\3 \2;;
+      s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^ 0-9]*)-([0-9a-zA-Z_-]{11}\r|ph[0-9a-f]{13}\r|[0-9]{8}\r)(.*)$;\1-\r\3 \2\n;;
+      t;
+      s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^ 0-9]*)([0-9]+)(.*)$;\1\r\3 \2;;
       tX;' \
       tX;' \
-    | { sort -n -k7 |sort -s -k6,6; echo '0 0 0 tags= comment= _'; } \
+    | { sort -n -k7 -k8 -k9 -k10 -k11 |sort -s -k6,6 ; echo '0 0 0 tags= comment= _'; } \
     | while read -r length h w t c name; do
       if [ "${ln%% *}" = "${name%% *}" ]; then
         al=$((al + length))
     | while read -r length h w t c name; do
       if [ "${ln%% *}" = "${name%% *}" ]; then
         al=$((al + length))
@@ -111,7 +114,7 @@ list_order(){
       fi
       ln="$name"
     done \
       fi
       ln="$name"
     done \
-    | sort -s -n -k1 |sed -r 's;^[0-9]+\t;metashort\t;;' \
+    | sort -s -n -k1,1 |sed -E 's;^[0-9]+\t;metashort\t;;' \
     | sed -E ':X s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\r]*)\r([^ ]*) ([^ ]+)( .*)?$;\1\3\2\4;; tX'
   elif [ $ORDER = Length ]; then
     sort -sn -k1 |sed 's;^;metashort\t;;'
     | sed -E ':X s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\r]*)\r([^ ]*) ([^ ]+)( .*)?$;\1\3\2\4;; tX'
   elif [ $ORDER = Length ]; then
     sort -sn -k1 |sed 's;^;metashort\t;;'
@@ -122,7 +125,7 @@ list_order(){
       printf '%i       %s      %s\n' \
              "$(stat -c %Y "$fn")" "${fm%      *}" "$fn"
     done \
       printf '%i       %s      %s\n' \
              "$(stat -c %Y "$fn")" "${fm%      *}" "$fn"
     done \
-    | sort -srn -k1 |sed -r 's;^[0-9]+\t;metalong\t;;'
+    | sort -srn -k1 |sed -E 's;^[0-9]+\t;metalong\t;;'
   fi
 }
 
   fi
 }