2012-03-07 04:20:30 +04:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# $1 - action
|
|
|
|
# $2 - type of file
|
|
|
|
|
|
|
|
action=$1
|
|
|
|
filetype=$2
|
|
|
|
|
2012-12-18 09:43:06 +04:00
|
|
|
[ -n "${MC_XDG_OPEN}" ] || MC_XDG_OPEN="xdg-open"
|
2012-03-07 04:20:30 +04:00
|
|
|
|
2012-05-18 19:42:26 +04:00
|
|
|
STAROFFICE_REGEXP='\.(sxw|sdw|stw|sxc|stc|sxi|sti|sxd|std||sxm||sxg)$'
|
|
|
|
|
|
|
|
staroffice_console() {
|
|
|
|
filename=$1;shift
|
|
|
|
is_view=$1; shift
|
|
|
|
if [ -n "${is_view}" ]; then
|
|
|
|
is_view='-dump'
|
|
|
|
fi
|
|
|
|
|
|
|
|
tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
|
|
|
|
cd $tmp
|
|
|
|
soffice2html.pl "${filename}"
|
|
|
|
elinks ${is_view} content.html
|
|
|
|
rm -rf "$tmp"
|
|
|
|
}
|
|
|
|
|
2012-10-05 12:30:01 +04:00
|
|
|
get_ooffice_executable() {
|
2020-10-09 00:59:32 +03:00
|
|
|
if which loffice >/dev/null 2>&1; then
|
2018-08-19 17:20:13 +03:00
|
|
|
echo "loffice"
|
2020-10-09 00:59:32 +03:00
|
|
|
elif which ooffice >/dev/null 2>&1; then
|
2012-10-05 12:30:01 +04:00
|
|
|
echo "ooffice"
|
2018-08-19 17:20:13 +03:00
|
|
|
else
|
|
|
|
echo -n
|
|
|
|
fi
|
2012-10-05 12:30:01 +04:00
|
|
|
}
|
|
|
|
|
2012-03-07 04:20:30 +04:00
|
|
|
do_view_action() {
|
|
|
|
filetype=$1
|
|
|
|
|
|
|
|
case "${filetype}" in
|
|
|
|
ps)
|
|
|
|
ps2ascii "${MC_EXT_FILENAME}"
|
|
|
|
;;
|
|
|
|
pdf)
|
2012-05-18 19:42:26 +04:00
|
|
|
pdftotext -layout -nopgbrk "${MC_EXT_FILENAME}" -
|
2012-03-07 04:20:30 +04:00
|
|
|
;;
|
|
|
|
odt)
|
2012-05-18 19:42:26 +04:00
|
|
|
if [ ` echo "${MC_EXT_FILENAME}" | grep -c "${STAROFFICE_REGEXP}"` -ne 0 ]; then
|
|
|
|
staroffice_console "${MC_EXT_FILENAME}" "view"
|
|
|
|
else
|
|
|
|
odt2txt "${MC_EXT_FILENAME}"
|
|
|
|
fi
|
2012-03-07 04:20:30 +04:00
|
|
|
;;
|
|
|
|
msdoc)
|
2020-10-09 00:59:32 +03:00
|
|
|
if which wvHtml >/dev/null 2>&1; then
|
2012-05-18 19:42:26 +04:00
|
|
|
tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
|
|
|
|
wvHtml "${MC_EXT_FILENAME}" --targetdir="$tmp" page.html
|
|
|
|
elinks -dump "$tmp/page.html"
|
|
|
|
rm -rf "$tmp"
|
2020-10-09 00:59:32 +03:00
|
|
|
elif which antiword >/dev/null 2>&1; then
|
2018-07-21 18:06:38 +03:00
|
|
|
antiword -t "${MC_EXT_FILENAME}"
|
2020-10-09 00:59:32 +03:00
|
|
|
elif which catdoc >/dev/null 2>&1; then
|
2018-07-21 18:06:38 +03:00
|
|
|
catdoc -w "${MC_EXT_FILENAME}"
|
2020-10-09 00:59:32 +03:00
|
|
|
elif which word2x >/dev/null 2>&1; then
|
2018-07-21 18:06:38 +03:00
|
|
|
word2x -f text "${MC_EXT_FILENAME}" -
|
|
|
|
else
|
2012-03-07 04:20:30 +04:00
|
|
|
strings "${MC_EXT_FILENAME}"
|
2018-07-21 18:06:38 +03:00
|
|
|
fi
|
2012-03-07 04:20:30 +04:00
|
|
|
;;
|
|
|
|
msxls)
|
2020-10-09 00:59:32 +03:00
|
|
|
if which xlhtml >/dev/null 2>&1; then
|
2012-05-18 19:42:26 +04:00
|
|
|
tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
|
|
|
|
xlhtml -a "${MC_EXT_FILENAME}" > "$tmp/page.html"
|
|
|
|
elinks -dump "$tmp/page.html"
|
|
|
|
rm -rf "$tmp"
|
2020-10-09 00:59:32 +03:00
|
|
|
elif which xls2csv >/dev/null 2>&1; then
|
2018-07-21 18:06:38 +03:00
|
|
|
xls2csv "${MC_EXT_FILENAME}"
|
|
|
|
else
|
2012-03-07 04:20:30 +04:00
|
|
|
strings "${MC_EXT_FILENAME}"
|
2018-07-21 18:06:38 +03:00
|
|
|
fi
|
2012-03-07 04:20:30 +04:00
|
|
|
;;
|
|
|
|
dvi)
|
2012-10-05 11:50:13 +04:00
|
|
|
which dvi2tty >/dev/null 2>&1 && \
|
|
|
|
dvi2tty "${MC_EXT_FILENAME}" || \
|
|
|
|
catdvi "${MC_EXT_FILENAME}"
|
2012-03-07 04:20:30 +04:00
|
|
|
;;
|
|
|
|
djvu)
|
|
|
|
djvused -e print-pure-txt "${MC_EXT_FILENAME}"
|
|
|
|
;;
|
2021-02-19 16:31:04 +03:00
|
|
|
ebook)
|
2012-10-05 13:48:15 +04:00
|
|
|
einfo -v "${MC_EXT_FILENAME}"
|
|
|
|
;;
|
2012-03-07 04:20:30 +04:00
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
do_open_action() {
|
|
|
|
filetype=$1
|
|
|
|
|
|
|
|
case "${filetype}" in
|
|
|
|
ps)
|
2012-05-18 19:42:26 +04:00
|
|
|
if [ -n "$DISPLAY" ]; then
|
|
|
|
(gv "${MC_EXT_FILENAME}" &)
|
|
|
|
else
|
|
|
|
ps2ascii "${MC_EXT_FILENAME}" | ${PAGER:-more}
|
|
|
|
fi
|
2012-03-07 04:20:30 +04:00
|
|
|
;;
|
|
|
|
pdf)
|
2012-10-05 11:56:41 +04:00
|
|
|
if [ ! -n "$DISPLAY" ]; then
|
2012-05-18 19:42:26 +04:00
|
|
|
pdftotext -layout -nopgbrk "${MC_EXT_FILENAME}" - | ${PAGER:-more}
|
2012-10-05 11:56:41 +04:00
|
|
|
elif see > /dev/null 2>&1; then
|
|
|
|
(see "${MC_EXT_FILENAME}" &)
|
|
|
|
else
|
|
|
|
(xpdf "${MC_EXT_FILENAME}" &)
|
2012-05-18 19:42:26 +04:00
|
|
|
fi
|
2012-03-07 04:20:30 +04:00
|
|
|
#(acroread "${MC_EXT_FILENAME}" &)
|
|
|
|
#(ghostview "${MC_EXT_FILENAME}" &)
|
|
|
|
;;
|
|
|
|
ooffice)
|
2012-05-18 19:42:26 +04:00
|
|
|
if [ -n "$DISPLAY" ]; then
|
2012-10-05 12:30:01 +04:00
|
|
|
OOFFICE=`get_ooffice_executable`
|
2018-08-19 17:20:13 +03:00
|
|
|
if [ -n "${OOFFICE}" ]; then
|
|
|
|
(${OOFFICE} "${MC_EXT_FILENAME}" &)
|
|
|
|
fi
|
2012-05-18 19:42:26 +04:00
|
|
|
else
|
2012-10-05 12:30:01 +04:00
|
|
|
if [ `echo "${MC_EXT_FILENAME}" | grep -c "${STAROFFICE_REGEXP}"` -ne 0 ]; then
|
2012-05-18 19:42:26 +04:00
|
|
|
staroffice_console "${MC_EXT_FILENAME}"
|
|
|
|
else
|
|
|
|
odt2txt "${MC_EXT_FILENAME}" | ${PAGER:-more}
|
|
|
|
fi
|
|
|
|
fi
|
2012-03-07 04:20:30 +04:00
|
|
|
;;
|
|
|
|
abw)
|
|
|
|
(abiword "${MC_EXT_FILENAME}" &)
|
|
|
|
;;
|
2012-09-23 10:48:04 +04:00
|
|
|
gnumeric)
|
|
|
|
(gnumeric "${MC_EXT_FILENAME}" &)
|
|
|
|
;;
|
2012-03-07 04:20:30 +04:00
|
|
|
msdoc)
|
2012-05-18 19:42:26 +04:00
|
|
|
if [ -n "$DISPLAY" ]; then
|
2018-08-19 17:20:13 +03:00
|
|
|
OOFFICE=`get_ooffice_executable`
|
|
|
|
if [ -n "${OOFFICE}" ]; then
|
|
|
|
(${OOFFICE} "${MC_EXT_FILENAME}" &)
|
|
|
|
else
|
|
|
|
(abiword "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
|
|
|
|
fi
|
2012-05-18 19:42:26 +04:00
|
|
|
else
|
|
|
|
tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
|
|
|
|
wvHtml "${MC_EXT_FILENAME}" --targetdir="$tmp" page.html -1
|
|
|
|
elinks "$tmp/page.html"
|
|
|
|
rm -rf "$tmp"
|
|
|
|
fi
|
2012-03-07 04:20:30 +04:00
|
|
|
;;
|
|
|
|
msxls)
|
2012-05-18 19:42:26 +04:00
|
|
|
if [ -n "$DISPLAY" ]; then
|
2018-08-19 17:20:13 +03:00
|
|
|
OOFFICE=`get_ooffice_executable`
|
|
|
|
if [ -n "${OOFFICE}" ]; then
|
|
|
|
(${OOFFICE} "${MC_EXT_FILENAME}" &)
|
|
|
|
else
|
|
|
|
(gnumeric "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
|
|
|
|
fi
|
2012-05-18 19:42:26 +04:00
|
|
|
else
|
|
|
|
tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
|
|
|
|
xlhtml -a "${MC_EXT_FILENAME}" > "$tmp/page.html"
|
|
|
|
elinks "$tmp/page.html"
|
|
|
|
rm -rf "$tmp"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
msppt)
|
|
|
|
if [ -n "$DISPLAY" ]; then
|
2012-10-05 12:30:01 +04:00
|
|
|
OOFFICE=`get_ooffice_executable`
|
2018-08-19 17:20:13 +03:00
|
|
|
if [ -n "${OOFFICE}" ]; then
|
|
|
|
(${OOFFICE} "${MC_EXT_FILENAME}" &)
|
|
|
|
fi
|
2012-05-18 19:42:26 +04:00
|
|
|
else
|
|
|
|
tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
|
2013-04-22 15:00:09 +04:00
|
|
|
ppthtml "${MC_EXT_FILENAME}" > "$tmp/page.html"
|
2012-05-18 19:42:26 +04:00
|
|
|
elinks "$tmp/page.html"
|
|
|
|
rm -rf "$tmp"
|
|
|
|
fi
|
2012-03-07 04:20:30 +04:00
|
|
|
;;
|
|
|
|
framemaker)
|
|
|
|
fmclient -f "${MC_EXT_FILENAME}"
|
|
|
|
;;
|
|
|
|
dvi)
|
2012-06-26 16:39:31 +04:00
|
|
|
if [ -n "$DISPLAY" ]; then
|
|
|
|
(xdvi "${MC_EXT_FILENAME}" &)
|
|
|
|
else
|
2012-05-18 19:42:26 +04:00
|
|
|
dvisvga "${MC_EXT_FILENAME}" || \
|
|
|
|
dvi2tty "${MC_EXT_FILENAME}" | ${PAGER:-more}
|
2012-03-07 04:20:30 +04:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
djvu)
|
|
|
|
djview "${MC_EXT_FILENAME}" &
|
|
|
|
;;
|
2012-10-05 13:44:47 +04:00
|
|
|
comic)
|
|
|
|
cbrpager "${MC_EXT_FILENAME}" &
|
|
|
|
;;
|
2021-02-19 16:31:04 +03:00
|
|
|
ebook)
|
2012-10-05 13:48:15 +04:00
|
|
|
lucidor "${MC_EXT_FILENAME}" >/dev/null &
|
|
|
|
;;
|
2012-03-07 04:20:30 +04:00
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
case "${action}" in
|
|
|
|
view)
|
|
|
|
do_view_action "${filetype}"
|
|
|
|
;;
|
|
|
|
open)
|
2016-02-14 08:40:57 +03:00
|
|
|
("${MC_XDG_OPEN}" "${MC_EXT_FILENAME}" >/dev/null 2>&1) || \
|
2012-03-07 04:20:30 +04:00
|
|
|
do_open_action "${filetype}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|