Ticket #3940: add Meson syntax highlighting.
[midnight-commander.git] / misc / ext.d / text.sh.in
blob2bd6ca05c5d4ba29070e3bee90786b80e7906893
1 #!/bin/sh
3 # $1 - action
4 # $2 - type of archive
5 # $3 - pager
7 action=$1
8 filetype=$2
9 pager=$3
11 [ -n "${MC_XDG_OPEN}" ] || MC_XDG_OPEN="xdg-open"
13 get_unpacker() {
14 filetype=$1
15 case "${filetype}" in
16 man.gz)
17 unpacker="gzip -dc"
19 man.bz)
20 unpacker="bzip -dc"
22 man.bz2)
23 unpacker="bzip2 -dc"
25 man.lz)
26 unpacker="lzip -dc"
28 man.lz4)
29 unpacker="lz4 -dc"
31 man.lzma)
32 unpacker="lzma -dc"
34 man.xz)
35 unpacker="xz -dc"
37 man.zst)
38 unpacker="zstd -dc"
40 esac
41 echo ${unpacker}
45 do_view_action() {
46 filetype=$1
48 unpacker=`get_unpacker ${filetype}`
50 case "${filetype}" in
51 man)
52 case "${MC_EXT_FILENAME}" in
53 */log/*|*/logs/*)
54 cat "${MC_EXT_FILENAME}"
57 MANROFFOPT=-c MAN_KEEP_FORMATTING=1 man -P cat "${MC_EXT_FILENAME}"
59 esac
61 pod)
62 pod2man "${MC_EXT_FILENAME}" | nroff @MAN_FLAGS@ @MANDOC@
64 nroff.me)
65 nroff @MAN_FLAGS@ -me "${MC_EXT_FILENAME}"
67 nroff.ms)
68 nroff @MAN_FLAGS@ -ms "${MC_EXT_FILENAME}"
70 man.gz|man.bz|man.bz2|man.lz|man.lz4|man.lzma|man.xz|man.zst)
71 case "${MC_EXT_FILENAME}" in
72 */log/*|*/logs/*)
73 ${unpacker} "${MC_EXT_FILENAME}"
76 # "man" takes care of uncompressing.
77 # This way the stdin is left intact so the correct width is used.
78 MANROFFOPT=-c MAN_KEEP_FORMATTING=1 man -P cat "${MC_EXT_FILENAME}"
80 esac
84 esac
87 do_open_action() {
88 filetype=$1
89 pager=$2
91 unpacker=`get_unpacker ${filetype}`
93 case "${filetype}" in
94 info)
95 info -f "${MC_EXT_FILENAME}"
97 man)
98 case "${MC_EXT_FILENAME}" in
99 */log/*|*/logs/*)
100 cat "${MC_EXT_FILENAME}"
103 { zsoelim "${MC_EXT_FILENAME}" 2>/dev/null || cat "${MC_EXT_FILENAME}"; } | \
104 nroff @MAN_FLAGS@ @MANDOC@
106 esac | ${pager}
108 pod)
109 pod2man "${MC_EXT_FILENAME}" | nroff @MAN_FLAGS@ @MANDOC@ | ${pager}
111 nroff.me)
112 nroff @MAN_FLAGS@ -me "${MC_EXT_FILENAME}" | ${pager}
114 nroff.ms)
115 nroff @MAN_FLAGS@ -ms "${MC_EXT_FILENAME}" | ${pager}
117 man.gz|man.bz|man.bz2|man.lz|man.lz4|man.lzma|man.xz|man.zst)
118 case "${MC_EXT_FILENAME}" in
119 */log/*|*/logs/*)
120 ${unpacker} "${MC_EXT_FILENAME}"
123 ${unpacker} "${MC_EXT_FILENAME}" | nroff @MAN_FLAGS@ @MANDOC@
125 esac | ${pager}
127 chm)
128 if [ -n "$DISPLAY" ]; then
129 which kchmviewer > /dev/null 2>&1 \
130 && (kchmviewer "${MC_EXT_FILENAME}" &) \
131 || (xchm "${MC_EXT_FILENAME}" &)
132 else
133 chm_http "${MC_EXT_FILENAME}" & elinks http://localhost:8080/index.html
134 kill -INT %1
139 esac
142 case "${action}" in
143 view)
144 do_view_action "${filetype}"
146 open)
147 ("${MC_XDG_OPEN}" "${MC_EXT_FILENAME}" >/dev/null 2>&1) || \
148 do_open_action "${filetype}" "${pager}"
152 esac