doc.sh.in 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #!/bin/sh
  2. # $1 - action
  3. # $2 - type of file
  4. action=$1
  5. filetype=$2
  6. [ -n "${MC_XDG_OPEN}" ] || MC_XDG_OPEN="xdg-open"
  7. STAROFFICE_REGEXP='\.(sxw|sdw|stw|sxc|stc|sxi|sti|sxd|std||sxm||sxg)$'
  8. staroffice_console() {
  9. filename=$1;shift
  10. is_view=$1; shift
  11. if [ -n "${is_view}" ]; then
  12. is_view='-dump'
  13. fi
  14. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  15. cd $tmp
  16. soffice2html.pl "${filename}"
  17. elinks ${is_view} content.html
  18. rm -rf "$tmp"
  19. }
  20. get_ooffice_executable() {
  21. if which loffice >/dev/null 2>&1; then
  22. echo "loffice"
  23. elif which ooffice >/dev/null 2>&1; then
  24. echo "ooffice"
  25. else
  26. echo -n
  27. fi
  28. }
  29. do_view_action() {
  30. filetype=$1
  31. case "${filetype}" in
  32. ps)
  33. ps2ascii "${MC_EXT_FILENAME}"
  34. ;;
  35. pdf)
  36. pdftotext -layout -nopgbrk "${MC_EXT_FILENAME}" -
  37. ;;
  38. odt)
  39. if [ ` echo "${MC_EXT_FILENAME}" | grep -c "${STAROFFICE_REGEXP}"` -ne 0 ]; then
  40. staroffice_console "${MC_EXT_FILENAME}" "view"
  41. else
  42. odt2txt "${MC_EXT_FILENAME}"
  43. fi
  44. ;;
  45. msdoc)
  46. if which wvHtml >/dev/null 2>&1; then
  47. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  48. wvHtml "${MC_EXT_FILENAME}" --targetdir="$tmp" page.html
  49. elinks -dump "$tmp/page.html"
  50. rm -rf "$tmp"
  51. elif which antiword >/dev/null 2>&1; then
  52. antiword -t "${MC_EXT_FILENAME}"
  53. elif which catdoc >/dev/null 2>&1; then
  54. catdoc -w "${MC_EXT_FILENAME}"
  55. elif which word2x >/dev/null 2>&1; then
  56. word2x -f text "${MC_EXT_FILENAME}" -
  57. else
  58. strings "${MC_EXT_FILENAME}"
  59. fi
  60. ;;
  61. msxls)
  62. if which xlhtml >/dev/null 2>&1; then
  63. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  64. xlhtml -a "${MC_EXT_FILENAME}" > "$tmp/page.html"
  65. elinks -dump "$tmp/page.html"
  66. rm -rf "$tmp"
  67. elif which xls2csv >/dev/null 2>&1; then
  68. xls2csv "${MC_EXT_FILENAME}"
  69. else
  70. strings "${MC_EXT_FILENAME}"
  71. fi
  72. ;;
  73. dvi)
  74. which dvi2tty >/dev/null 2>&1 && \
  75. dvi2tty "${MC_EXT_FILENAME}" || \
  76. catdvi "${MC_EXT_FILENAME}"
  77. ;;
  78. djvu)
  79. djvused -e print-pure-txt "${MC_EXT_FILENAME}"
  80. ;;
  81. ebook)
  82. einfo -v "${MC_EXT_FILENAME}"
  83. ;;
  84. *)
  85. ;;
  86. esac
  87. }
  88. do_open_action() {
  89. filetype=$1
  90. case "${filetype}" in
  91. ps)
  92. if [ -n "$DISPLAY" ]; then
  93. (gv "${MC_EXT_FILENAME}" &)
  94. else
  95. ps2ascii "${MC_EXT_FILENAME}" | ${PAGER:-more}
  96. fi
  97. ;;
  98. pdf)
  99. if [ ! -n "$DISPLAY" ]; then
  100. pdftotext -layout -nopgbrk "${MC_EXT_FILENAME}" - | ${PAGER:-more}
  101. elif see > /dev/null 2>&1; then
  102. (see "${MC_EXT_FILENAME}" &)
  103. else
  104. (xpdf "${MC_EXT_FILENAME}" &)
  105. fi
  106. #(acroread "${MC_EXT_FILENAME}" &)
  107. #(ghostview "${MC_EXT_FILENAME}" &)
  108. ;;
  109. ooffice)
  110. if [ -n "$DISPLAY" ]; then
  111. OOFFICE=`get_ooffice_executable`
  112. if [ -n "${OOFFICE}" ]; then
  113. (${OOFFICE} "${MC_EXT_FILENAME}" &)
  114. fi
  115. else
  116. if [ `echo "${MC_EXT_FILENAME}" | grep -c "${STAROFFICE_REGEXP}"` -ne 0 ]; then
  117. staroffice_console "${MC_EXT_FILENAME}"
  118. else
  119. odt2txt "${MC_EXT_FILENAME}" | ${PAGER:-more}
  120. fi
  121. fi
  122. ;;
  123. abw)
  124. (abiword "${MC_EXT_FILENAME}" &)
  125. ;;
  126. gnumeric)
  127. (gnumeric "${MC_EXT_FILENAME}" &)
  128. ;;
  129. msdoc)
  130. if [ -n "$DISPLAY" ]; then
  131. OOFFICE=`get_ooffice_executable`
  132. if [ -n "${OOFFICE}" ]; then
  133. (${OOFFICE} "${MC_EXT_FILENAME}" &)
  134. else
  135. (abiword "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
  136. fi
  137. else
  138. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  139. wvHtml "${MC_EXT_FILENAME}" --targetdir="$tmp" page.html -1
  140. elinks "$tmp/page.html"
  141. rm -rf "$tmp"
  142. fi
  143. ;;
  144. msxls)
  145. if [ -n "$DISPLAY" ]; then
  146. OOFFICE=`get_ooffice_executable`
  147. if [ -n "${OOFFICE}" ]; then
  148. (${OOFFICE} "${MC_EXT_FILENAME}" &)
  149. else
  150. (gnumeric "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
  151. fi
  152. else
  153. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  154. xlhtml -a "${MC_EXT_FILENAME}" > "$tmp/page.html"
  155. elinks "$tmp/page.html"
  156. rm -rf "$tmp"
  157. fi
  158. ;;
  159. msppt)
  160. if [ -n "$DISPLAY" ]; then
  161. OOFFICE=`get_ooffice_executable`
  162. if [ -n "${OOFFICE}" ]; then
  163. (${OOFFICE} "${MC_EXT_FILENAME}" &)
  164. fi
  165. else
  166. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  167. ppthtml "${MC_EXT_FILENAME}" > "$tmp/page.html"
  168. elinks "$tmp/page.html"
  169. rm -rf "$tmp"
  170. fi
  171. ;;
  172. framemaker)
  173. fmclient -f "${MC_EXT_FILENAME}"
  174. ;;
  175. dvi)
  176. if [ -n "$DISPLAY" ]; then
  177. (xdvi "${MC_EXT_FILENAME}" &)
  178. else
  179. dvisvga "${MC_EXT_FILENAME}" || \
  180. dvi2tty "${MC_EXT_FILENAME}" | ${PAGER:-more}
  181. fi
  182. ;;
  183. djvu)
  184. djview "${MC_EXT_FILENAME}" &
  185. ;;
  186. comic)
  187. cbrpager "${MC_EXT_FILENAME}" &
  188. ;;
  189. ebook)
  190. lucidor "${MC_EXT_FILENAME}" >/dev/null &
  191. ;;
  192. *)
  193. ;;
  194. esac
  195. }
  196. case "${action}" in
  197. view)
  198. do_view_action "${filetype}"
  199. ;;
  200. open)
  201. ("${MC_XDG_OPEN}" "${MC_EXT_FILENAME}" >/dev/null 2>&1) || \
  202. do_open_action "${filetype}"
  203. ;;
  204. *)
  205. ;;
  206. esac