doc.sh.in 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. which loffice >/dev/null 2>&1 && \
  22. echo "loffice" || \
  23. echo "ooffice"
  24. }
  25. do_view_action() {
  26. filetype=$1
  27. case "${filetype}" in
  28. ps)
  29. ps2ascii "${MC_EXT_FILENAME}"
  30. ;;
  31. pdf)
  32. pdftotext -layout -nopgbrk "${MC_EXT_FILENAME}" -
  33. ;;
  34. odt)
  35. if [ ` echo "${MC_EXT_FILENAME}" | grep -c "${STAROFFICE_REGEXP}"` -ne 0 ]; then
  36. staroffice_console "${MC_EXT_FILENAME}" "view"
  37. else
  38. odt2txt "${MC_EXT_FILENAME}"
  39. fi
  40. ;;
  41. msdoc)
  42. which wvHtml >/dev/null 2>&1 &&
  43. {
  44. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  45. wvHtml "${MC_EXT_FILENAME}" --targetdir="$tmp" page.html
  46. elinks -dump "$tmp/page.html"
  47. rm -rf "$tmp"
  48. } || \
  49. antiword -t "${MC_EXT_FILENAME}" || \
  50. catdoc -w "${MC_EXT_FILENAME}" || \
  51. word2x -f text "${MC_EXT_FILENAME}" - || \
  52. strings "${MC_EXT_FILENAME}"
  53. ;;
  54. msxls)
  55. which xlHtml >/dev/null 2>&1 && {
  56. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  57. xlhtml -a "${MC_EXT_FILENAME}" > "$tmp/page.html"
  58. elinks -dump "$tmp/page.html"
  59. rm -rf "$tmp"
  60. } || \
  61. xls2csv "${MC_EXT_FILENAME}" || \
  62. strings "${MC_EXT_FILENAME}"
  63. ;;
  64. dvi)
  65. which dvi2tty >/dev/null 2>&1 && \
  66. dvi2tty "${MC_EXT_FILENAME}" || \
  67. catdvi "${MC_EXT_FILENAME}"
  68. ;;
  69. djvu)
  70. djvused -e print-pure-txt "${MC_EXT_FILENAME}"
  71. ;;
  72. epub)
  73. einfo -v "${MC_EXT_FILENAME}"
  74. ;;
  75. *)
  76. ;;
  77. esac
  78. }
  79. do_open_action() {
  80. filetype=$1
  81. case "${filetype}" in
  82. ps)
  83. if [ -n "$DISPLAY" ]; then
  84. (gv "${MC_EXT_FILENAME}" &)
  85. else
  86. ps2ascii "${MC_EXT_FILENAME}" | ${PAGER:-more}
  87. fi
  88. ;;
  89. pdf)
  90. if [ ! -n "$DISPLAY" ]; then
  91. pdftotext -layout -nopgbrk "${MC_EXT_FILENAME}" - | ${PAGER:-more}
  92. elif see > /dev/null 2>&1; then
  93. (see "${MC_EXT_FILENAME}" &)
  94. else
  95. (xpdf "${MC_EXT_FILENAME}" &)
  96. fi
  97. #(acroread "${MC_EXT_FILENAME}" &)
  98. #(ghostview "${MC_EXT_FILENAME}" &)
  99. ;;
  100. ooffice)
  101. if [ -n "$DISPLAY" ]; then
  102. OOFFICE=`get_ooffice_executable`
  103. (${OOFFICE} "${MC_EXT_FILENAME}" &)
  104. else
  105. if [ `echo "${MC_EXT_FILENAME}" | grep -c "${STAROFFICE_REGEXP}"` -ne 0 ]; then
  106. staroffice_console "${MC_EXT_FILENAME}"
  107. else
  108. odt2txt "${MC_EXT_FILENAME}" | ${PAGER:-more}
  109. fi
  110. fi
  111. ;;
  112. abw)
  113. (abiword "${MC_EXT_FILENAME}" &)
  114. ;;
  115. gnumeric)
  116. (gnumeric "${MC_EXT_FILENAME}" &)
  117. ;;
  118. msdoc)
  119. if [ -n "$DISPLAY" ]; then
  120. (abiword "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
  121. else
  122. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  123. wvHtml "${MC_EXT_FILENAME}" --targetdir="$tmp" page.html -1
  124. elinks "$tmp/page.html"
  125. rm -rf "$tmp"
  126. fi
  127. ;;
  128. msxls)
  129. if [ -n "$DISPLAY" ]; then
  130. (gnumeric "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
  131. else
  132. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  133. xlhtml -a "${MC_EXT_FILENAME}" > "$tmp/page.html"
  134. elinks "$tmp/page.html"
  135. rm -rf "$tmp"
  136. fi
  137. ;;
  138. msppt)
  139. if [ -n "$DISPLAY" ]; then
  140. OOFFICE=`get_ooffice_executable`
  141. (${OOFFICE} "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
  142. else
  143. tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
  144. ppthtml "${MC_EXT_FILENAME}" > "$tmp/page.html"
  145. elinks "$tmp/page.html"
  146. rm -rf "$tmp"
  147. fi
  148. ;;
  149. framemaker)
  150. fmclient -f "${MC_EXT_FILENAME}"
  151. ;;
  152. dvi)
  153. if [ -n "$DISPLAY" ]; then
  154. (xdvi "${MC_EXT_FILENAME}" &)
  155. else
  156. dvisvga "${MC_EXT_FILENAME}" || \
  157. dvi2tty "${MC_EXT_FILENAME}" | ${PAGER:-more}
  158. fi
  159. ;;
  160. djvu)
  161. djview "${MC_EXT_FILENAME}" &
  162. ;;
  163. comic)
  164. cbrpager "${MC_EXT_FILENAME}" &
  165. ;;
  166. epub)
  167. lucidor "${MC_EXT_FILENAME}" >/dev/null &
  168. ;;
  169. *)
  170. ;;
  171. esac
  172. }
  173. case "${action}" in
  174. view)
  175. do_view_action "${filetype}"
  176. ;;
  177. open)
  178. "${MC_XDG_OPEN}" "${MC_EXT_FILENAME}" 2>/dev/null || \
  179. do_open_action "${filetype}"
  180. ;;
  181. *)
  182. ;;
  183. esac