diff options
-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 |