-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrlo
executable file
·57 lines (51 loc) · 1.54 KB
/
rlo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#! /bin/bash
SCRIPT=`basename ${BASH_SOURCE[0]}`
ARGS=("$@")
# Print usage and exit
function USAGE {
echo -e "\nOpen Reading List. Usage: $SCRIPT 'topic'"
echo -e "Usage: $SCRIPT 'topic'"
echo -e "\nOpen all the documents on a specified topic in a given reading list"
echo -e "(created, for example, by the companion 'rlc' script)."
echo -e "\nThe input is a series of comma separated value (CSV) lines read from standard"
echo -e "input consisting of a topic tag and absolute path to a document/file."
echo -e "\nOptions recognized:"
echo -e "-h -- Print usage message and exit"
echo -e "-f -- Read input from named file (default: read from STDIN)"
echo -e "-a -- The application name (default: Preview)"
echo -e "\nAll remaining positional (non-option) parameters are concatenated (joined with"
echo -e "a blank separator) and used as the reading list topic tag (default: all topics)\n"
exit 1
}
# Option defaults
APP="Preview"
FILE="STDIN"
# Command line options
while getopts :ha:f: OPT; do
case $OPT in
a)
APP=$OPTARG
;;
f)
FILE=$OPTARG
;;
h)
USAGE
;;
\?)
echo -e "\nInvalid command line option - $OPTARG"
USAGE
;;
esac
done
# Optionally redirect output and append to specified file
[ "$FILE" != "STDIN" ] && exec < $FILE
# Join remaining command line arguments
IND=$(expr $OPTIND - 1)
REST=("${ARGS[@]:$IND}")
TOPIC=${REST[@]:-".*"}
# Open files with matching topic tag
FILES=$(grep "^$TOPIC" <&0 | awk '{print $2}')
for FILE in $FILES; do
open -a $APP $FILE
done