From 59e9e99551eb5889b1efa077c8b2ffa97c2eccf9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Sun, 24 May 2020 15:38:13 +0200 Subject: [PATCH] improved grouping, improved shell compatibility --- list.sh | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) 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 } -- 2.39.2