From: Paul Hänsch Date: Sun, 24 May 2020 13:38:13 +0000 (+0200) Subject: improved grouping, improved shell compatibility X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=59e9e99551eb5889b1efa077c8b2ffa97c2eccf9;p=serve0 improved grouping, improved shell compatibility --- diff --git a/list.sh b/list.sh index 58eb062..8ba460e 100644 --- a/list.sh +++ b/list.sh @@ -49,12 +49,12 @@ list_item() { [ "$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 - [ ! "${f#~}" ] && continue - [ "${f#~}" = "$f" ] \ + [ "${f#\~}" ] || continue + [ "${f#\~}" = "$f" ] \ && 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 @@ -71,15 +71,16 @@ list_fullname(){ 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}" \ - | 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}" \ - | sed -r ':x s;((^|[^\\])(\\\\)*)\+;\1 ;g; tx; + | sed -E ':x s;((^|[^\\])(\\\\)*)\+;\1 ;g; tx; s;((^|[^\\])(\\\\)*)\\\+;\1+;g; s; ;\\+;g;')" else @@ -95,9 +96,11 @@ list_order(){ 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;' \ - | { 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)) @@ -111,7 +114,7 @@ list_order(){ 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;;' @@ -122,7 +125,7 @@ list_order(){ 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 }