text.sh.in 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #!/bin/sh
  2. # $1 - action
  3. # $2 - type of archive
  4. # $3 - pager
  5. action=$1
  6. filetype=$2
  7. pager=$3
  8. [ -n "${MC_XDG_OPEN}" ] || MC_XDG_OPEN="xdg-open"
  9. get_unpacker() {
  10. filetype=$1
  11. case "${filetype}" in
  12. man.gz)
  13. unpacker="gzip -dc"
  14. ;;
  15. man.bz)
  16. unpacker="bzip -dc"
  17. ;;
  18. man.bz2)
  19. unpacker="bzip2 -dc"
  20. ;;
  21. man.lz)
  22. unpacker="lzip -dc"
  23. ;;
  24. man.lz4)
  25. unpacker="lz4 -dc"
  26. ;;
  27. man.lzma)
  28. unpacker="lzma -dc"
  29. ;;
  30. man.lzo)
  31. unpacker="lzop -dc"
  32. ;;
  33. man.xz)
  34. unpacker="xz -dc"
  35. ;;
  36. man.zst)
  37. unpacker="zstd -dc"
  38. ;;
  39. esac
  40. echo ${unpacker}
  41. }
  42. do_view_action() {
  43. filetype=$1
  44. unpacker=`get_unpacker ${filetype}`
  45. case "${filetype}" in
  46. man)
  47. case "${MC_EXT_FILENAME}" in
  48. */log/*|*/logs/*)
  49. cat "${MC_EXT_FILENAME}"
  50. ;;
  51. *)
  52. MANROFFOPT=-c MAN_KEEP_FORMATTING=1 man -P cat "${MC_EXT_FILENAME}"
  53. ;;
  54. esac
  55. ;;
  56. pod)
  57. pod2man "${MC_EXT_FILENAME}" | nroff @MAN_FLAGS@ @MANDOC@
  58. ;;
  59. nroff.me)
  60. nroff @MAN_FLAGS@ -me "${MC_EXT_FILENAME}"
  61. ;;
  62. nroff.ms)
  63. nroff @MAN_FLAGS@ -ms "${MC_EXT_FILENAME}"
  64. ;;
  65. man.gz|man.bz|man.bz2|man.lz|man.lz4|man.lzma|man.lzo|man.xz|man.zst)
  66. case "${MC_EXT_FILENAME}" in
  67. */log/*|*/logs/*)
  68. ${unpacker} "${MC_EXT_FILENAME}"
  69. ;;
  70. *)
  71. # "man" takes care of uncompressing.
  72. # This way the stdin is left intact so the correct width is used.
  73. MANROFFOPT=-c MAN_KEEP_FORMATTING=1 man -P cat "${MC_EXT_FILENAME}"
  74. ;;
  75. esac
  76. ;;
  77. *)
  78. ;;
  79. esac
  80. }
  81. do_open_action() {
  82. filetype=$1
  83. pager=$2
  84. unpacker=`get_unpacker ${filetype}`
  85. case "${filetype}" in
  86. info)
  87. info -f "${MC_EXT_FILENAME}"
  88. ;;
  89. man)
  90. case "${MC_EXT_FILENAME}" in
  91. */log/*|*/logs/*)
  92. cat "${MC_EXT_FILENAME}"
  93. ;;
  94. *)
  95. { zsoelim "${MC_EXT_FILENAME}" 2>/dev/null || cat "${MC_EXT_FILENAME}"; } | \
  96. nroff @MAN_FLAGS@ @MANDOC@
  97. ;;
  98. esac | ${pager}
  99. ;;
  100. pod)
  101. pod2man "${MC_EXT_FILENAME}" | nroff @MAN_FLAGS@ @MANDOC@ | ${pager}
  102. ;;
  103. nroff.me)
  104. nroff @MAN_FLAGS@ -me "${MC_EXT_FILENAME}" | ${pager}
  105. ;;
  106. nroff.ms)
  107. nroff @MAN_FLAGS@ -ms "${MC_EXT_FILENAME}" | ${pager}
  108. ;;
  109. man.gz|man.bz|man.bz2|man.lz|man.lz4|man.lzma|man.lzo|man.xz|man.zst)
  110. case "${MC_EXT_FILENAME}" in
  111. */log/*|*/logs/*)
  112. ${unpacker} "${MC_EXT_FILENAME}"
  113. ;;
  114. *)
  115. ${unpacker} "${MC_EXT_FILENAME}" | nroff @MAN_FLAGS@ @MANDOC@
  116. ;;
  117. esac | ${pager}
  118. ;;
  119. chm)
  120. if [ -n "$DISPLAY" ]; then
  121. command -v kchmviewer >/dev/null 2>&1 \
  122. && (kchmviewer "${MC_EXT_FILENAME}" &) \
  123. || (xchm "${MC_EXT_FILENAME}" &)
  124. else
  125. chm_http "${MC_EXT_FILENAME}" & elinks http://localhost:8080/index.html
  126. kill -INT %1
  127. fi
  128. ;;
  129. *)
  130. ;;
  131. esac
  132. }
  133. case "${action}" in
  134. view)
  135. do_view_action "${filetype}"
  136. ;;
  137. open)
  138. ("${MC_XDG_OPEN}" "${MC_EXT_FILENAME}" >/dev/null 2>&1) || \
  139. do_open_action "${filetype}" "${pager}"
  140. ;;
  141. *)
  142. ;;
  143. esac