]> gitweb.fluxo.info Git - scripts.git/commitdiff
Feat: show: automatically update the filelist
authorSilvio Rhatto <rhatto@riseup.net>
Mon, 2 Nov 2020 21:37:35 +0000 (18:37 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Mon, 2 Nov 2020 21:37:35 +0000 (18:37 -0300)
show

diff --git a/show b/show
index a3c6ff503d87fd96549fef614d7f9a928c372b25..a2f717955e9146d1763aefe881f326dc91258777 100755 (executable)
--- 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 <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