diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2020-11-02 18:37:35 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2020-11-02 18:37:35 -0300 |
commit | 5c1c193fea476f7d99fcdf87b5b93008288a2d17 (patch) | |
tree | 6ffc8929c703de477ef8416672b1469222e22177 | |
parent | aac6cc1fe41986300e46b3bc5015b47cee3378ff (diff) | |
download | scripts-5c1c193fea476f7d99fcdf87b5b93008288a2d17.tar.gz scripts-5c1c193fea476f7d99fcdf87b5b93008288a2d17.tar.bz2 |
Feat: show: automatically update the filelist
-rwxr-xr-x | show | 29 |
1 files changed, 26 insertions, 3 deletions
@@ -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 <item-name>" 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 |