From 7854ce57a1708324ae178fb3f3bef2752483ee4d Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 3 Aug 2024 16:16:23 -0300 Subject: Fix: rename 'show' as 'docshower' --- docshower | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ show | 125 -------------------------------------------------------------- 2 files changed, 125 insertions(+), 125 deletions(-) create mode 100755 docshower delete mode 100755 show diff --git a/docshower b/docshower new file mode 100755 index 0000000..102baae --- /dev/null +++ b/docshower @@ -0,0 +1,125 @@ +#!/bin/bash +# +# Fast way to browse documents stored in an archive. +# + +# Parameters +PROGRAM="$0" +BASENAME="`basename $0`" +DOCS="$HOME/data/doc" +BIBLIO="$DOCS/bibliographies" +FILELIST=".doclist" +LIST="$DOCS/$FILELIST" +DOC_PATTERN=".*\.(txt|doc|docx|rtf|pdf|sxc|csv|odt|odf|ods|xls|xlsx|ppt|epub|mobi|djvu|lit)" +FIND_OPTS="-regextype posix-egrep -iregex" +ARG="$1" +EXTRA_ARG="$2" +DATE="`date +%s`" +MAX_AGE="86400" + +# Update the filelist +function __update_filelist { + echo "Generating new filelist..." + + # Unnanex if it was erroneously annexed + if [ -h "$LIST" ] && [ -d "$DOCS/.git/annex" ]; then + ( cd $DOCS && git annex unlock $FILELIST ) + fi + + # Refresh + cd $DOCS && find . -not -path '*.git*' $FIND_OPTS "$DOC_PATTERN" > $LIST + + # Stage + git add $LIST +} + +# Check +if [ -z "$ARG" ]; then + echo "usage: $BASENAME [option] [] [extra-args]" + echo " $BASENAME --refresh" + echo " $BASENAME -- " + echo " $BASENAME --open " + echo " $BASENAME --rifle -p 4" + echo " $BASENAME --koreader " + echo " $BASENAME --watch " + echo " $BASENAME " + exit 1 + +elif [ "$ARG" == "--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 "*$ARG*" | head -1 | while read entry; do xdg-open "$entry"; done +if [ "$ARG" == "--search" ]; then + shift + grep -i -- "$*" $LIST + +elif [ "$ARG" == "--details" ]; then + shift + entry="`echo $* | sed -e 's/^@//'`" + if grep -qiR -- "$entry" $BIBLIO; then + grep -iR -- "$entry" $BIBLIO | cut -d : -f 1 | while read file; do + echo "At $file:" + echo "" + # Thanks https://tex.stackexchange.com/questions/28506/how-to-use-a-command-line-tool-to-extract-a-bibtex-reference-that-contains-a-sea + awk -v RS='\n@' "/${entry}/" $file + done + else + find $DOCS -name ${1}.bib -exec cat {} \; + fi + +elif [ "$ARG" == "--watch" ]; then + # Convert symlink to full path and start inotifywait loop + folder="`readlink -f $DOCS`" + subfolder="$EXTRA_ARG" + echo "Watching changes at $folder/$subfolder..." + + #while inotifywait -e modify -e create -e move -e delete -r "$folder"; do + #while inotifywait -e modify -e move -r "$folder"; do + #while inotifywait -e modify -e move -r "$folder/$subfolder"; do + #while inotifywait -e modify -e create -e move -e delete -r "$folder/$subfolder"; do + # $PROGRAM --refresh + #done + inotifier $PROGRAM --refresh + +else + shift 2 + EXTRA_ARGS="$*" + + # Allows for specifying a custom command to open the file + if [ "${ARG:0:2}" == "--" ] && [ ! -z "$EXTRA_ARG" ]; then + OPEN="${ARG:2}" + ARG="$EXTRA_ARG" + + # Shortcuts for xdg-open + if [ "$OPEN" == "open" ] || [ "$OPEN" == "read" ]; then + OPEN="xdg-open" + fi + else + OPEN="xdg-open" + EXTRA_ARGS="" + fi + + grep -i -- "$ARG" $LIST | while read entry; do + echo "Opening $entry..." + cd $DOCS && $OPEN $EXTRA_ARGS "$entry" + done +fi diff --git a/show b/show deleted file mode 100755 index 102baae..0000000 --- a/show +++ /dev/null @@ -1,125 +0,0 @@ -#!/bin/bash -# -# Fast way to browse documents stored in an archive. -# - -# Parameters -PROGRAM="$0" -BASENAME="`basename $0`" -DOCS="$HOME/data/doc" -BIBLIO="$DOCS/bibliographies" -FILELIST=".doclist" -LIST="$DOCS/$FILELIST" -DOC_PATTERN=".*\.(txt|doc|docx|rtf|pdf|sxc|csv|odt|odf|ods|xls|xlsx|ppt|epub|mobi|djvu|lit)" -FIND_OPTS="-regextype posix-egrep -iregex" -ARG="$1" -EXTRA_ARG="$2" -DATE="`date +%s`" -MAX_AGE="86400" - -# Update the filelist -function __update_filelist { - echo "Generating new filelist..." - - # Unnanex if it was erroneously annexed - if [ -h "$LIST" ] && [ -d "$DOCS/.git/annex" ]; then - ( cd $DOCS && git annex unlock $FILELIST ) - fi - - # Refresh - cd $DOCS && find . -not -path '*.git*' $FIND_OPTS "$DOC_PATTERN" > $LIST - - # Stage - git add $LIST -} - -# Check -if [ -z "$ARG" ]; then - echo "usage: $BASENAME [option] [] [extra-args]" - echo " $BASENAME --refresh" - echo " $BASENAME -- " - echo " $BASENAME --open " - echo " $BASENAME --rifle -p 4" - echo " $BASENAME --koreader " - echo " $BASENAME --watch " - echo " $BASENAME " - exit 1 - -elif [ "$ARG" == "--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 "*$ARG*" | head -1 | while read entry; do xdg-open "$entry"; done -if [ "$ARG" == "--search" ]; then - shift - grep -i -- "$*" $LIST - -elif [ "$ARG" == "--details" ]; then - shift - entry="`echo $* | sed -e 's/^@//'`" - if grep -qiR -- "$entry" $BIBLIO; then - grep -iR -- "$entry" $BIBLIO | cut -d : -f 1 | while read file; do - echo "At $file:" - echo "" - # Thanks https://tex.stackexchange.com/questions/28506/how-to-use-a-command-line-tool-to-extract-a-bibtex-reference-that-contains-a-sea - awk -v RS='\n@' "/${entry}/" $file - done - else - find $DOCS -name ${1}.bib -exec cat {} \; - fi - -elif [ "$ARG" == "--watch" ]; then - # Convert symlink to full path and start inotifywait loop - folder="`readlink -f $DOCS`" - subfolder="$EXTRA_ARG" - echo "Watching changes at $folder/$subfolder..." - - #while inotifywait -e modify -e create -e move -e delete -r "$folder"; do - #while inotifywait -e modify -e move -r "$folder"; do - #while inotifywait -e modify -e move -r "$folder/$subfolder"; do - #while inotifywait -e modify -e create -e move -e delete -r "$folder/$subfolder"; do - # $PROGRAM --refresh - #done - inotifier $PROGRAM --refresh - -else - shift 2 - EXTRA_ARGS="$*" - - # Allows for specifying a custom command to open the file - if [ "${ARG:0:2}" == "--" ] && [ ! -z "$EXTRA_ARG" ]; then - OPEN="${ARG:2}" - ARG="$EXTRA_ARG" - - # Shortcuts for xdg-open - if [ "$OPEN" == "open" ] || [ "$OPEN" == "read" ]; then - OPEN="xdg-open" - fi - else - OPEN="xdg-open" - EXTRA_ARGS="" - fi - - grep -i -- "$ARG" $LIST | while read entry; do - echo "Opening $entry..." - cd $DOCS && $OPEN $EXTRA_ARGS "$entry" - done -fi -- cgit v1.2.3