From ee2a0b2dc2a7a72f6c7cb16fa5108c5597637e7d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Mon, 16 Jul 2018 12:05:56 +0200 Subject: [PATCH] unify listing, enable search --- list.sh | 82 +++++++++++++++++++++++---------------------------------- 1 file changed, 33 insertions(+), 49 deletions(-) diff --git a/list.sh b/list.sh index 03b9845..607ea20 100644 --- a/list.sh +++ b/list.sh @@ -28,62 +28,36 @@ list_item() { fi } -list_fs_browse(){ - meta_dir "$_DATA/$ITEM" - (cd "$_DATA/$ITEM"; - find ./ -type d \! -name .index -mindepth 1 -maxdepth 1 \ - -exec stat -c '%Y %n' '{}' + - find ./ -type f -mindepth 1 -maxdepth 1 \ - -exec stat -c '%Y %n' '{}' + - ) -} -list_fs_index(){ - local d - find "$_DATA/$ITEM" -type d -name .index \ - | while d="$(line)"; do - meta_dir "${d%/.index}" - done - (cd "$_DATA/$ITEM"; - find ./ \! -path '*/.index/*' -type f \ - -exec stat -c '%Y %n' '{}' + - ) -} - -list_browse(){ - local meta f fn file - meta="$_DATA/$ITEM/.index/meta" - meta_dir "$_DATA/$ITEM" +list_directories(){ (cd "$_DATA/$ITEM"; find ./ -type d \! -name .index -mindepth 1 -maxdepth 1 \ ) | cut -d/ -f2- | sort - sort -n "$meta" | cut -f6- \ +} + +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- \ | while f="$(line)"; do fn="$(UNSTRING "${f#* }")"; fn="${fn%${CR}}"; - file="$(printf '%s\n' "$_DATA/$ITEM/${fn}".*)" + file="$(printf '%s\n' "$_DATA/$ITEM/$base/${fn}".*)" file="${file##*/}" - [ -e "$_DATA/$ITEM/${file}" ] \ - && printf '%s\n' "${file}" + [ -e "$_DATA/$ITEM/$base/${file}" ] \ + && printf '%s %s\n' "${f%% *}" "${base}/${file}" done } list_index(){ - local meta base fn file + local meta (cd "$_DATA/$ITEM"; find ./ -path '*/.index/meta' ) | while meta="$(line)"; do - base="${meta%/.index/meta}" - meta_dir "$_DATA/$ITEM/$base" - cut -f1,6- <"$_DATA/$ITEM/$meta" \ - | while f="$(line)"; do - fn="$(UNSTRING "${f#* }")"; fn="${fn%${CR}}"; - file="$(printf '%s\n' "$_DATA/$ITEM/$base/${fn}".*)" - file="${file##*/}" - [ -e "$_DATA/$ITEM/$base/${file}" ] \ - && printf '%s %s\n' "${f%% *}" "${base}/${file}" - done - done \ - | sort -n \ - | cut -d/ -f2- + list_filemeta "${meta%/.index/meta}" + done } list_items() { @@ -93,17 +67,27 @@ list_items() { [ "$mode" = browse -a "$ITEM" ] && printf '..\n' if [ "$mode" = browse -a "$ORDER" = Date ]; then - list_fs_browse | sort -rn | cut -d/ -f2- + list_directories + list_filemeta . |cut -f2- \ + | xargs -d\n stat -c '%Y %n' \ + | sort -rn |cut -d/ -f2- elif [ "$mode" = browse -a "$ORDER" = Name ]; then - list_fs_browse | sort -k 2 | cut -d/ -f2- + list_directories + list_filemeta . \ + | sort -k 2 |cut -d/ -f2- elif [ "$mode" = index -a "$ORDER" = Date ]; then - list_fs_index | sort -rn | cut -d/ -f2- + list_index |cut -f2- \ + | xargs -d'\n' stat -c '%Y %n' \ + | sort -rn | cut -d/ -f2- elif [ "$mode" = index -a "$ORDER" = Name ]; then - list_fs_index | sort -k 2 | cut -d/ -f2- + list_index | sort -k 2 | cut -d/ -f2- elif [ "$mode" = browse -a "$ORDER" = Length ]; then - list_browse + list_directories + list_filemeta . \ + | sort -n |cut -d/ -f2- elif [ "$mode" = index -a "$ORDER" = Length ]; then - list_index + list_index \ + | sort -n |cut -d/ -f2- fi } -- 2.39.2