Ticket #4536: skins: add root variant of julia256 skin.
[midnight-commander.git] / misc / ext.d / doc.sh.in
blobc296ca270ec44019075dd25ecf35fa6776e8a649
1 #!/bin/sh
3 # $1 - action
4 # $2 - type of file
6 action=$1
7 filetype=$2
9 [ -n "${MC_XDG_OPEN}" ] || MC_XDG_OPEN="xdg-open"
11 STAROFFICE_REGEXP='\.(sxw|sdw|stw|sxc|stc|sxi|sti|sxd|std||sxm||sxg)$'
13 staroffice_console() {
14 filename=$1;shift
15 is_view=$1; shift
16 if [ -n "${is_view}" ]; then
17 is_view='-dump'
20 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
21 cd $tmp
22 soffice2html.pl "${filename}"
23 elinks ${is_view} content.html
24 rm -rf "$tmp"
27 get_ooffice_executable() {
28 if which loffice >/dev/null 2>&1; then
29 echo "loffice"
30 elif which ooffice >/dev/null 2>&1; then
31 echo "ooffice"
32 else
33 echo -n
37 do_view_action() {
38 filetype=$1
40 case "${filetype}" in
41 ps)
42 ps2ascii "${MC_EXT_FILENAME}"
44 pdf)
45 pdftotext -layout -nopgbrk "${MC_EXT_FILENAME}" -
47 odt)
48 if [ ` echo "${MC_EXT_FILENAME}" | grep -c "${STAROFFICE_REGEXP}"` -ne 0 ]; then
49 staroffice_console "${MC_EXT_FILENAME}" "view"
50 else
51 odt2txt "${MC_EXT_FILENAME}"
54 msdoc)
55 if which wvHtml >/dev/null 2>&1; then
56 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
57 wvHtml "${MC_EXT_FILENAME}" --targetdir="$tmp" page.html
58 elinks -dump "$tmp/page.html"
59 rm -rf "$tmp"
60 elif which antiword >/dev/null 2>&1; then
61 antiword -t "${MC_EXT_FILENAME}"
62 elif which catdoc >/dev/null 2>&1; then
63 catdoc -w "${MC_EXT_FILENAME}"
64 elif which word2x >/dev/null 2>&1; then
65 word2x -f text "${MC_EXT_FILENAME}" -
66 else
67 strings "${MC_EXT_FILENAME}"
70 msxls)
71 if which xlhtml >/dev/null 2>&1; then
72 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
73 xlhtml -a "${MC_EXT_FILENAME}" > "$tmp/page.html"
74 elinks -dump "$tmp/page.html"
75 rm -rf "$tmp"
76 elif which xls2csv >/dev/null 2>&1; then
77 xls2csv "${MC_EXT_FILENAME}"
78 else
79 strings "${MC_EXT_FILENAME}"
82 dvi)
83 which dvi2tty >/dev/null 2>&1 && \
84 dvi2tty "${MC_EXT_FILENAME}" || \
85 catdvi "${MC_EXT_FILENAME}"
87 djvu)
88 djvused -e print-pure-txt "${MC_EXT_FILENAME}"
90 ebook)
91 einfo -v "${MC_EXT_FILENAME}"
95 esac
98 do_open_action() {
99 filetype=$1
101 case "${filetype}" in
103 if [ -n "$DISPLAY" ]; then
104 (gv "${MC_EXT_FILENAME}" &)
105 else
106 ps2ascii "${MC_EXT_FILENAME}" | ${PAGER:-more}
109 pdf)
110 if [ ! -n "$DISPLAY" ]; then
111 pdftotext -layout -nopgbrk "${MC_EXT_FILENAME}" - | ${PAGER:-more}
112 elif see > /dev/null 2>&1; then
113 (see "${MC_EXT_FILENAME}" &)
114 else
115 (xpdf "${MC_EXT_FILENAME}" &)
117 #(acroread "${MC_EXT_FILENAME}" &)
118 #(ghostview "${MC_EXT_FILENAME}" &)
120 ooffice)
121 if [ -n "$DISPLAY" ]; then
122 OOFFICE=`get_ooffice_executable`
123 if [ -n "${OOFFICE}" ]; then
124 (${OOFFICE} "${MC_EXT_FILENAME}" &)
126 else
127 if [ `echo "${MC_EXT_FILENAME}" | grep -c "${STAROFFICE_REGEXP}"` -ne 0 ]; then
128 staroffice_console "${MC_EXT_FILENAME}"
129 else
130 odt2txt "${MC_EXT_FILENAME}" | ${PAGER:-more}
134 abw)
135 (abiword "${MC_EXT_FILENAME}" &)
137 gnumeric)
138 (gnumeric "${MC_EXT_FILENAME}" &)
140 msdoc)
141 if [ -n "$DISPLAY" ]; then
142 OOFFICE=`get_ooffice_executable`
143 if [ -n "${OOFFICE}" ]; then
144 (${OOFFICE} "${MC_EXT_FILENAME}" &)
145 else
146 (abiword "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
148 else
149 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
150 wvHtml "${MC_EXT_FILENAME}" --targetdir="$tmp" page.html -1
151 elinks "$tmp/page.html"
152 rm -rf "$tmp"
155 msxls)
156 if [ -n "$DISPLAY" ]; then
157 OOFFICE=`get_ooffice_executable`
158 if [ -n "${OOFFICE}" ]; then
159 (${OOFFICE} "${MC_EXT_FILENAME}" &)
160 else
161 (gnumeric "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
163 else
164 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
165 xlhtml -a "${MC_EXT_FILENAME}" > "$tmp/page.html"
166 elinks "$tmp/page.html"
167 rm -rf "$tmp"
170 msppt)
171 if [ -n "$DISPLAY" ]; then
172 OOFFICE=`get_ooffice_executable`
173 if [ -n "${OOFFICE}" ]; then
174 (${OOFFICE} "${MC_EXT_FILENAME}" &)
176 else
177 tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
178 ppthtml "${MC_EXT_FILENAME}" > "$tmp/page.html"
179 elinks "$tmp/page.html"
180 rm -rf "$tmp"
183 framemaker)
184 fmclient -f "${MC_EXT_FILENAME}"
186 dvi)
187 if [ -n "$DISPLAY" ]; then
188 (xdvi "${MC_EXT_FILENAME}" &)
189 else
190 dvisvga "${MC_EXT_FILENAME}" || \
191 dvi2tty "${MC_EXT_FILENAME}" | ${PAGER:-more}
194 djvu)
195 djview "${MC_EXT_FILENAME}" &
197 comic)
198 cbrpager "${MC_EXT_FILENAME}" &
200 ebook)
201 lucidor "${MC_EXT_FILENAME}" >/dev/null &
205 esac
208 case "${action}" in
209 view)
210 do_view_action "${filetype}"
212 open)
213 ("${MC_XDG_OPEN}" "${MC_EXT_FILENAME}" >/dev/null 2>&1) || \
214 do_open_action "${filetype}"
218 esac