-
Notifications
You must be signed in to change notification settings - Fork 0
/
osxman
executable file
·85 lines (57 loc) · 1.38 KB
/
osxman
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh
# osxman - open man pages using x-man-page:// on MacOSX
# based on: https://scriptingosx.com/2022/11/on-viewing-man-pages-ventura-update/
# secure file permissions
umask 077
# terminate on errors and unset variables
set -eu
# global variables
# external programs
PGM_OPEN="/usr/bin/open"
PGM_MAN="/usr/bin/man"
PGM_MANDOC="/usr/bin/mandoc"
# PDF mode
ARG_PDF="-pdf"
# url for man pages
MAN_URL="x-man-page://"
# functions
print_usage() {
echo "Usage: $0 [$ARG_PDF] [section] manpage" 1>&2
}
print_error() {
echo "Error: " "$@" 1>&2
}
# check to see if open is executable
if [ ! -x "$PGM_OPEN" ] ; then
print_error "$PGM_OPEN not executable!" ;
exit 1 ;
fi
# display man pages as PDF if -pdf is specified
if [ X"$1" = X"$ARG_PDF" ] ; then
shift
if [ $# -lt 1 ] ; then
print_usage ;
exit 1 ;
fi
for PGM in "$PGM_MAN" "$PGM_MANDOC"
do
if [ ! -x "$PGM" ] ; then
print_error "$PGM not executable!" ;
exit 1 ;
fi
done
"$PGM_MANDOC" -T pdf "`$PGM_MAN -w $@`" | \
"$PGM_OPEN" -fa Preview
exit $?
fi
# if only the man page is specified, just open it
if [ $# -eq 1 ] ; then
exec "$PGM_OPEN" "$MAN_URL$1"
fi
# if a section is specified, open that man page
if [ $# -eq 2 ] ; then
exec "$PGM_OPEN" "$MAN_URL$1/$2"
fi
# print a usage statement and exit
print_usage
exit 0