From 5c1c193fea476f7d99fcdf87b5b93008288a2d17 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Mon, 2 Nov 2020 18:37:35 -0300 Subject: Feat: show: automatically update the filelist --- show | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/show b/show index a3c6ff5..a2f7179 100755 --- a/show +++ b/show @@ -1,6 +1,6 @@ #!/bin/bash # -# View a document. +# Fast way to browse documents stored in an archive. # # Parameters @@ -8,13 +8,36 @@ BASENAME="`basename $0`" DOCS="$HOME/data/doc" LIST="$DOCS/.filelist" ITEM="$1" +DATE="`date +%s`" +MAX_AGE="86400" + +# Update the filelist +function __update_filelist { + find $DOCS -not -path '*.git*' > $FILELIST +} # Check if [ -z "$ITEM" ]; then echo "usage: $BASENAME " exit 1 +elif [ ! -d "$DOCS" ]; then + echo "missing $DOCS folder" + exit 1 +fi + +# Check for filelist +if [ ! -e "$FILELIST" ]; then + __update_filelist + CHANGED="`date +%s`" +else + CHANGED="`stat --printf='%Y\n' $LIST`" +fi + +# Refresh lists older than $MAG_AGE +if ((($DATE - $CHANGED) >= $MAG_AGE)); then + __update_filelist fi # Dispatch -#find $DOCS -iname "*$ITEM*" | head -1 | while read item; do xdg-open "$item"; done -grep "$ITEM" $LIST | while read item; do xdg-open "$item"; done +#find $DOCS -iname "*$ITEM*" | head -1 | while read entry; do xdg-open "$entry"; done +grep -- "$ITEM" $LIST | while read entry; do xdg-open "$entry"; done -- cgit v1.2.3