-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader
More file actions
executable file
·47 lines (40 loc) · 1.15 KB
/
reader
File metadata and controls
executable file
·47 lines (40 loc) · 1.15 KB
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
#!/bin/sh
# reader — open markdown files in Reader.app.
#
# reader launch Reader (no document)
# reader <file>... open one or more files
#
# Paths are resolved to absolute before being handed to Launch Services
# so Reader's document handler receives them correctly regardless of the
# shell's current working directory.
set -e
BUNDLE_ID="com.jefflarson.Reader"
case "${1:-}" in
-h|--help)
cat <<EOF
reader — open markdown files in Reader.app
reader launch Reader
reader <file>... open files in Reader
reader -h show this help
EOF
exit 0
;;
esac
if [ $# -eq 0 ]; then
exec /usr/bin/open -b "$BUNDLE_ID"
fi
absolute_paths=""
for arg in "$@"; do
if [ ! -e "$arg" ]; then
echo "reader: $arg: no such file" >&2
exit 1
fi
abs="$(/usr/bin/dirname "$arg")"
abs="$(cd "$abs" && pwd)/$(/usr/bin/basename "$arg")"
absolute_paths="$absolute_paths
$abs"
done
# Pass each path as a separate argument via xargs so paths with spaces
# survive untouched.
printf '%s' "$absolute_paths" | /usr/bin/tr '\n' '\0' \
| /usr/bin/xargs -0 /usr/bin/open -b "$BUNDLE_ID"