#!/bin/bash # # Fast way to browse documents stored in an archive. # # Parameters BASENAME="`basename $0`" DOCS="$HOME/data/doc" LIST="$DOCS/.filelist" DOC_PATTERN=".*\.(txt|doc|docx|rtf|pdf|sxc|csv|odt|odf|ods|xls|xlsx|ppt|epub|mobi|djvu|lit)" FIND_OPTS="-not -path '*.git*' -regextype posix-egrep -iregex" ITEM="$1" DATE="`date +%s`" MAX_AGE="86400" # Update the filelist function __update_filelist { echo "Generating new filelist..." cd $DOCS && find . $FIND_OPTS "$DOC_PATTERN" > $LIST } # Check if [ -z "$ITEM" ]; then echo "usage: $BASENAME " exit 1 elif [ "$ITEM" == "--refresh" ]; then __update_filelist elif [ ! -d "$DOCS" ]; then echo "missing $DOCS folder" exit 1 fi # Check for filelist if [ ! -e "$LIST" ]; then __update_filelist CHANGED="`date +%s`" else CHANGED="`stat --printf='%Y\n' $LIST`" fi # Automatically refresh lists older than $MAX_AGE #if ((($DATE - $CHANGED) >= $MAX_AGE)); then # __update_filelist #fi # Dispatch #find $DOCS -iname "*$ITEM*" | head -1 | while read entry; do xdg-open "$entry"; done if [ "$ITEM" == "--search" ]; then shift grep -i -- "$*" $LIST else grep -i -- "$ITEM" $LIST | while read entry; do echo "Opening $entry..." cd $DOCS && xdg-open "$entry" done fi