]>
Commit | Line | Data |
---|---|---|
98a34d2c | 1 | #!/bin/bash |
2 | # | |
3 | # Invoke whatever HTML viewer is installed... | |
4 | # Usage: | |
5 | # htmlview [--remote|--local] URL | |
6 | # --remote: We need support for remote (http/ftp) URLs | |
7 | # --local: This is a local (doc) html file | |
8 | # If neither --remote nor --local is given, it will | |
9 | # be determined automatically. | |
10 | # | |
11 | # List the tools in order of preference. | |
12 | # | |
13 | # written by Bernhard Rosenkraenzer <bero@redhat.com> | |
14 | # (c) 2000-2001 Red Hat, Inc. | |
15 | # | |
16 | # made insensitive on file extention and piped stdout detection | |
17 | # by Andrzej M. Krzysztofowicz <ankry@pld.org.pl> | |
18 | # | |
19 | # This script is in the public domain. | |
20 | ||
21 | if [ "$1" == "--remote" ]; then | |
22 | REMOTE=1 | |
23 | shift | |
24 | elif [ "$1" == "--local" ]; then | |
25 | REMOTE=0 | |
26 | shift | |
27 | else | |
28 | if echo $1 |egrep -q "^(http://|ftp://|www\.|ftp\.)" 2>/dev/null; then | |
29 | REMOTE=1 | |
30 | else | |
31 | REMOTE=0 | |
32 | fi | |
33 | fi | |
34 | if ls -l /proc/self/fd/1 | grep 'pipe:' >/dev/null 2>&1; then | |
35 | STDOUT_IS_PIPE=1 | |
36 | else | |
37 | STDOUT_IS_PIPE=0 | |
38 | fi | |
39 | ||
40 | ELINKS_CMD () | |
41 | { | |
42 | if [ "$1" = --name ] ; then | |
43 | echo /usr/bin/elinks | |
44 | elif [ "$1" = --dumpcmd ]; then | |
45 | shift | |
46 | echo -n /usr/bin/elinks -dump $* | |
47 | if [ $STDOUT_IS_PIPE = 0 ]; then | |
cb49bc10 | 48 | echo \| ${PAGER:-/bin/more} |
98a34d2c | 49 | else |
50 | echo | |
51 | fi | |
52 | else | |
53 | if [ $STDOUT_IS_PIPE = 0 ]; then | |
cb49bc10 | 54 | /usr/bin/elinks -dump $* | ${PAGER:-/bin/more} |
98a34d2c | 55 | else |
56 | /usr/bin/elinks -dump $* | |
57 | fi | |
58 | fi | |
59 | } | |
60 | LINKS_CMD () | |
61 | { | |
62 | if [ "$1" = --name ] ; then | |
63 | echo /usr/bin/links | |
64 | elif [ "$1" = --dumpcmd ]; then | |
65 | shift | |
66 | echo -n /usr/bin/links -dump $* | |
67 | if [ $STDOUT_IS_PIPE = 0 ]; then | |
cb49bc10 | 68 | echo \| ${PAGER:-/bin/more} |
98a34d2c | 69 | else |
70 | echo | |
71 | fi | |
72 | else | |
73 | if [ $STDOUT_IS_PIPE = 0 ]; then | |
cb49bc10 | 74 | /usr/bin/links -dump $* | ${PAGER:-/bin/more} |
98a34d2c | 75 | else |
76 | /usr/bin/links -dump $* | |
77 | fi | |
78 | fi | |
79 | } | |
80 | LYNX_CMD () | |
81 | { | |
82 | if [ "$1" = --name ]; then | |
83 | echo /usr/bin/lynx | |
84 | elif [ "$1" = --dumpcmd ]; then | |
85 | shift | |
86 | echo /usr/bin/lynx --force-html $* | |
87 | elif [ $STDOUT_IS_PIPE = 0 ]; then | |
88 | /usr/bin/lynx --force-html $* | |
89 | else | |
90 | /usr/bin/lynx --force-html -dump $* | |
91 | fi | |
92 | } | |
93 | W3M_CMD () | |
94 | { | |
95 | if [ "$1" = --name ] ; then | |
96 | echo /usr/bin/w3m | |
97 | elif [ "$1" = --dumpcmd ]; then | |
98 | shift | |
99 | echo /usr/bin/w3m -T text/html $* | |
100 | else | |
101 | /usr/bin/w3m -T text/html $* | |
102 | fi | |
103 | } | |
104 | IS_FUNC () | |
105 | { | |
106 | if declare -F | sed "s/^declare -f //" | grep "^$1\$" >/dev/null ; | |
107 | then | |
108 | return 0 | |
109 | else | |
110 | return 1 | |
111 | fi | |
112 | } | |
113 | IS_FUNC_WORKING () | |
114 | { | |
115 | IS_FUNC "$1" && test -x `$1 --name` | |
116 | } | |
117 | ||
118 | TERMS_KDE="/usr/bin/konsole /usr/bin/kvt" | |
119 | TERMS_GNOME="/usr/bin/gnome-terminal" | |
120 | TERMS_GENERIC="/usr/bin/rxvt /usr/X11R6/bin/xterm /usr/bin/Eterm" | |
121 | if [ $REMOTE == 1 ]; then | |
122 | TTYTOOLS="/usr/bin/elinks /usr/bin/links /usr/bin/lynx /usr/bin/w3m" | |
123 | X11TOOLS_KDE="/usr/bin/konqueror /usr/bin/kfmbrowser" | |
124 | X11TOOLS_GNOME="/usr/bin/galeon /usr/bin/mozilla" | |
125 | X11TOOLS_GENERIC="/usr/bin/mozilla /usr/bin/netscape" | |
126 | else | |
127 | TTYTOOLS="ELINKS_CMD LINKS_CMD LYNX_CMD W3M_CMD /usr/bin/less /bin/more /bin/cat" | |
128 | X11TOOLS_KDE="/usr/bin/khelpcenter /usr/bin/konqueror /usr/bin/khcclient /usr/bin/kdehelp /usr/bin/kfmbrowser" | |
129 | X11TOOLS_GNOME="/usr/bin/gnome-help-browser" | |
130 | X11TOOLS_GENERIC="/usr/bin/mozilla /usr/bin/netscape" | |
131 | fi | |
132 | ||
133 | if [ "x`/sbin/pidof gnome-session`" != "x" ]; then | |
134 | X11TOOLS="$X11TOOLS_GNOME $X11TOOLS_KDE $X11TOOLS_GENERIC" | |
135 | TERMS="$TERMS_GNOME $TERMS_KDE $TERMS_GENERIC" | |
136 | else | |
137 | X11TOOLS="$X11TOOLS_KDE $X11TOOLS_GNOME $X11TOOLS_GENERIC" | |
138 | TERMS="$TERMS_KDE $TERMS_GNOME $TERMS_GENERIC" | |
139 | fi | |
140 | ||
141 | if test "x$DISPLAY" = x; then | |
142 | for i in $TTYTOOLS; do | |
143 | if IS_FUNC_WORKING $i; then | |
144 | $i $* | |
145 | exit $? | |
146 | elif [ -x $i ]; then | |
147 | exec $i $* | |
148 | fi | |
149 | done | |
150 | else | |
151 | for i in $X11TOOLS; do | |
152 | [ -x $i ] && exec $i $* | |
153 | done | |
154 | for i in $TERMS; do | |
155 | if [ -x $i ]; then | |
156 | CONSOLE="$i -e" | |
157 | break | |
158 | fi | |
159 | done | |
160 | for i in $TTYTOOLS; do | |
161 | if IS_FUNC_WORKING $i; then | |
162 | exec $CONSOLE `$i --dumpcmd $*` | |
163 | elif [ -x $i ]; then | |
164 | exec $CONSOLE $i $* | |
165 | fi | |
166 | done | |
167 | fi |