aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xshow44
1 files changed, 30 insertions, 14 deletions
diff --git a/show b/show
index a68264b..004ef08 100755
--- a/show
+++ b/show
@@ -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