aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xshow29
1 files 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 <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