2012-03-07 04:20:30 +04:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# $1 - action
|
|
|
|
# $2 - type of archive
|
|
|
|
# $3 - pager
|
|
|
|
|
|
|
|
action=$1
|
|
|
|
filetype=$2
|
|
|
|
pager=$3
|
|
|
|
|
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
|
|
|
get_unpacker() {
|
|
|
|
filetype=$1
|
|
|
|
case "${filetype}" in
|
|
|
|
man.gz)
|
|
|
|
unpacker="gzip -dc"
|
|
|
|
;;
|
|
|
|
man.bz)
|
|
|
|
unpacker="bzip -dc"
|
|
|
|
;;
|
|
|
|
man.bz2)
|
|
|
|
unpacker="bzip2 -dc"
|
|
|
|
;;
|
2016-01-10 10:36:19 +03:00
|
|
|
man.lz)
|
|
|
|
unpacker="lzip -dc"
|
|
|
|
;;
|
2015-12-27 22:53:02 +03:00
|
|
|
man.lz4)
|
|
|
|
unpacker="lz4 -dc"
|
|
|
|
;;
|
2012-03-07 04:20:30 +04:00
|
|
|
man.lzma)
|
|
|
|
unpacker="lzma -dc"
|
|
|
|
;;
|
2023-11-19 17:30:37 +03:00
|
|
|
man.lzo)
|
|
|
|
unpacker="lzop -dc"
|
|
|
|
;;
|
2012-03-07 04:20:30 +04:00
|
|
|
man.xz)
|
|
|
|
unpacker="xz -dc"
|
|
|
|
;;
|
2018-03-18 20:23:33 +03:00
|
|
|
man.zst)
|
|
|
|
unpacker="zstd -dc"
|
|
|
|
;;
|
2012-03-07 04:20:30 +04:00
|
|
|
esac
|
|
|
|
echo ${unpacker}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
do_view_action() {
|
|
|
|
filetype=$1
|
|
|
|
|
|
|
|
unpacker=`get_unpacker ${filetype}`
|
|
|
|
|
|
|
|
case "${filetype}" in
|
|
|
|
man)
|
2013-12-11 15:24:44 +04:00
|
|
|
case "${MC_EXT_FILENAME}" in
|
2012-03-07 04:20:30 +04:00
|
|
|
*/log/*|*/logs/*)
|
|
|
|
cat "${MC_EXT_FILENAME}"
|
|
|
|
;;
|
|
|
|
*)
|
2016-01-03 08:36:55 +03:00
|
|
|
MANROFFOPT=-c MAN_KEEP_FORMATTING=1 man -P cat "${MC_EXT_FILENAME}"
|
2012-03-07 04:20:30 +04:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
pod)
|
|
|
|
pod2man "${MC_EXT_FILENAME}" | nroff @MAN_FLAGS@ @MANDOC@
|
|
|
|
;;
|
|
|
|
nroff.me)
|
|
|
|
nroff @MAN_FLAGS@ -me "${MC_EXT_FILENAME}"
|
|
|
|
;;
|
|
|
|
nroff.ms)
|
|
|
|
nroff @MAN_FLAGS@ -ms "${MC_EXT_FILENAME}"
|
|
|
|
;;
|
2023-11-19 17:30:37 +03:00
|
|
|
man.gz|man.bz|man.bz2|man.lz|man.lz4|man.lzma|man.lzo|man.xz|man.zst)
|
2013-12-11 15:24:44 +04:00
|
|
|
case "${MC_EXT_FILENAME}" in
|
2012-03-07 04:20:30 +04:00
|
|
|
*/log/*|*/logs/*)
|
2012-07-21 15:21:54 +04:00
|
|
|
${unpacker} "${MC_EXT_FILENAME}"
|
2012-03-07 04:20:30 +04:00
|
|
|
;;
|
|
|
|
*)
|
2014-09-02 15:31:15 +04:00
|
|
|
# "man" takes care of uncompressing.
|
|
|
|
# This way the stdin is left intact so the correct width is used.
|
2016-01-03 08:36:55 +03:00
|
|
|
MANROFFOPT=-c MAN_KEEP_FORMATTING=1 man -P cat "${MC_EXT_FILENAME}"
|
2012-07-21 15:21:54 +04:00
|
|
|
;;
|
2012-03-07 04:20:30 +04:00
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
do_open_action() {
|
|
|
|
filetype=$1
|
|
|
|
pager=$2
|
|
|
|
|
|
|
|
unpacker=`get_unpacker ${filetype}`
|
|
|
|
|
|
|
|
case "${filetype}" in
|
|
|
|
info)
|
|
|
|
info -f "${MC_EXT_FILENAME}"
|
|
|
|
;;
|
|
|
|
man)
|
2013-12-11 15:24:44 +04:00
|
|
|
case "${MC_EXT_FILENAME}" in
|
2012-03-07 04:20:30 +04:00
|
|
|
*/log/*|*/logs/*)
|
|
|
|
cat "${MC_EXT_FILENAME}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
{ zsoelim "${MC_EXT_FILENAME}" 2>/dev/null || cat "${MC_EXT_FILENAME}"; } | \
|
|
|
|
nroff @MAN_FLAGS@ @MANDOC@
|
|
|
|
;;
|
|
|
|
esac | ${pager}
|
|
|
|
;;
|
|
|
|
pod)
|
|
|
|
pod2man "${MC_EXT_FILENAME}" | nroff @MAN_FLAGS@ @MANDOC@ | ${pager}
|
|
|
|
;;
|
|
|
|
nroff.me)
|
|
|
|
nroff @MAN_FLAGS@ -me "${MC_EXT_FILENAME}" | ${pager}
|
|
|
|
;;
|
|
|
|
nroff.ms)
|
|
|
|
nroff @MAN_FLAGS@ -ms "${MC_EXT_FILENAME}" | ${pager}
|
|
|
|
;;
|
2023-11-19 17:30:37 +03:00
|
|
|
man.gz|man.bz|man.bz2|man.lz|man.lz4|man.lzma|man.lzo|man.xz|man.zst)
|
2013-12-11 15:24:44 +04:00
|
|
|
case "${MC_EXT_FILENAME}" in
|
2012-03-07 04:20:30 +04:00
|
|
|
*/log/*|*/logs/*)
|
|
|
|
${unpacker} "${MC_EXT_FILENAME}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
${unpacker} "${MC_EXT_FILENAME}" | nroff @MAN_FLAGS@ @MANDOC@
|
|
|
|
;;
|
|
|
|
esac | ${pager}
|
|
|
|
;;
|
|
|
|
chm)
|
2012-05-18 19:42:26 +04:00
|
|
|
if [ -n "$DISPLAY" ]; then
|
|
|
|
which kchmviewer > /dev/null 2>&1 \
|
|
|
|
&& (kchmviewer "${MC_EXT_FILENAME}" &) \
|
|
|
|
|| (xchm "${MC_EXT_FILENAME}" &)
|
|
|
|
else
|
|
|
|
chm_http "${MC_EXT_FILENAME}" & elinks http://localhost:8080/index.html
|
|
|
|
kill -INT %1
|
|
|
|
fi
|
2012-03-07 04:20:30 +04:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
case "${action}" in
|
|
|
|
view)
|
2012-07-21 15:21:54 +04:00
|
|
|
do_view_action "${filetype}"
|
2012-03-07 04:20:30 +04:00
|
|
|
;;
|
|
|
|
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}" "${pager}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|