diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2023-07-12 11:23:34 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2023-07-12 11:23:34 -0300 |
commit | 09fc011e92731d0dd78b44ff9681a761661c5a30 (patch) | |
tree | a83b82633e3c75b84dbd38238260d3d58421599d | |
parent | f0fad0ddc3920f9dd7787df7138f1d661d27fa5d (diff) | |
download | scripts-09fc011e92731d0dd78b44ff9681a761661c5a30.tar.gz scripts-09fc011e92731d0dd78b44ff9681a761661c5a30.tar.bz2 |
Improve the 'show' command (2)
-rwxr-xr-x | show | 44 |
1 files changed, 30 insertions, 14 deletions
@@ -11,8 +11,8 @@ FILELIST=".filelist" 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" -OPTION="$2" +ARG="$1" +EXTRA_ARG="$2" DATE="`date +%s`" MAX_AGE="86400" @@ -33,10 +33,17 @@ function __update_filelist { } # Check -if [ -z "$ITEM" ]; then - echo "usage: $BASENAME [option] [<item-name>]" +if [ -z "$ARG" ]; then + echo "usage: $BASENAME [option] [<object>] [extra-args]" + echo " $BASENAME --refresh" + echo " $BASENAME --<program-name> <item-name>" + echo " $BASENAME --open <item-name>" + echo " $BASENAME --rifle <item-name> -p 4" + echo " $BASENAME --koreader <item-name>" + echo " $BASENAME --watch <subfolder>" + echo " $BASENAME <item-name>" exit 1 -elif [ "$ITEM" == "--refresh" ]; then +elif [ "$ARG" == "--refresh" ]; then __update_filelist elif [ ! -d "$DOCS" ]; then echo "missing $DOCS folder" @@ -57,14 +64,14 @@ fi #fi # Dispatch -#find $DOCS -iname "*$ITEM*" | head -1 | while read entry; do xdg-open "$entry"; done -if [ "$ITEM" == "--search" ]; then +#find $DOCS -iname "*$ARG*" | head -1 | while read entry; do xdg-open "$entry"; done +if [ "$ARG" == "--search" ]; then shift grep -i -- "$*" $LIST -elif [ "$ITEM" == "--watch" ]; then +elif [ "$ARG" == "--watch" ]; then # Convert symlink to full path and start inotifywait loop folder="`readlink -f $DOCS`" - subfolder="$OPTION" + subfolder="$EXTRA_ARG" echo "Watching changes at $folder/$subfolder..." #while inotifywait -e modify -e create -e move -e delete -r "$folder"; do @@ -74,15 +81,24 @@ elif [ "$ITEM" == "--watch" ]; then $PROGRAM --refresh done else - if [ "${ITEM:0:2}" == "--" ] && [ ! -z "$OPTION" ]; then - OPEN="${ITEM:2}" - ITEM="$OPTION" + 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" fi - grep -i -- "$ITEM" $LIST | while read entry; do + grep -i -- "$ARG" $LIST | while read entry; do echo "Opening $entry..." - cd $DOCS && $OPEN "$entry" + cd $DOCS && $OPEN $EXTRA_ARGS "$entry" done fi |