text.sh.in 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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.lzma)
  22. unpacker="lzma -dc"
  23. ;;
  24. man.xz)
  25. unpacker="xz -dc"
  26. ;;
  27. esac
  28. echo ${unpacker}
  29. }
  30. do_view_action() {
  31. filetype=$1
  32. unpacker=`get_unpacker ${filetype}`
  33. case "${filetype}" in
  34. man)
  35. case "${MC_EXT_FILENAME}" in
  36. */log/*|*/logs/*)
  37. cat "${MC_EXT_FILENAME}"
  38. ;;
  39. *)
  40. MANROFFOPT=-c MAN_KEEP_FORMATTING=1 man -P cat -l "${MC_EXT_FILENAME}"
  41. ;;
  42. esac
  43. ;;
  44. pod)
  45. pod2man "${MC_EXT_FILENAME}" | nroff @MAN_FLAGS@ @MANDOC@
  46. ;;
  47. nroff.me)
  48. nroff @MAN_FLAGS@ -me "${MC_EXT_FILENAME}"
  49. ;;
  50. nroff.ms)
  51. nroff @MAN_FLAGS@ -ms "${MC_EXT_FILENAME}"
  52. ;;
  53. man.gz|man.bz|man.bz2|man.lzma|man.xz)
  54. case "${MC_EXT_FILENAME}" in
  55. */log/*|*/logs/*)
  56. ${unpacker} "${MC_EXT_FILENAME}"
  57. ;;
  58. *)
  59. # "man" takes care of uncompressing.
  60. # This way the stdin is left intact so the correct width is used.
  61. MANROFFOPT=-c MAN_KEEP_FORMATTING=1 man -P cat -l "${MC_EXT_FILENAME}"
  62. ;;
  63. esac
  64. ;;
  65. *)
  66. ;;
  67. esac
  68. }
  69. do_open_action() {
  70. filetype=$1
  71. pager=$2
  72. unpacker=`get_unpacker ${filetype}`
  73. case "${filetype}" in
  74. info)
  75. info -f "${MC_EXT_FILENAME}"
  76. ;;
  77. man)
  78. case "${MC_EXT_FILENAME}" in
  79. */log/*|*/logs/*)
  80. cat "${MC_EXT_FILENAME}"
  81. ;;
  82. *)
  83. { zsoelim "${MC_EXT_FILENAME}" 2>/dev/null || cat "${MC_EXT_FILENAME}"; } | \
  84. nroff @MAN_FLAGS@ @MANDOC@
  85. ;;
  86. esac | ${pager}
  87. ;;
  88. pod)
  89. pod2man "${MC_EXT_FILENAME}" | nroff @MAN_FLAGS@ @MANDOC@ | ${pager}
  90. ;;
  91. nroff.me)
  92. nroff @MAN_FLAGS@ -me "${MC_EXT_FILENAME}" | ${pager}
  93. ;;
  94. nroff.ms)
  95. nroff @MAN_FLAGS@ -ms "${MC_EXT_FILENAME}" | ${pager}
  96. ;;
  97. man.gz|man.bz|man.bz2|man.lzma|man.xz)
  98. case "${MC_EXT_FILENAME}" in
  99. */log/*|*/logs/*)
  100. ${unpacker} "${MC_EXT_FILENAME}"
  101. ;;
  102. *)
  103. ${unpacker} "${MC_EXT_FILENAME}" | nroff @MAN_FLAGS@ @MANDOC@
  104. ;;
  105. esac | ${pager}
  106. ;;
  107. chm)
  108. if [ -n "$DISPLAY" ]; then
  109. which kchmviewer > /dev/null 2>&1 \
  110. && (kchmviewer "${MC_EXT_FILENAME}" &) \
  111. || (xchm "${MC_EXT_FILENAME}" &)
  112. else
  113. chm_http "${MC_EXT_FILENAME}" & elinks http://localhost:8080/index.html
  114. kill -INT %1
  115. fi
  116. ;;
  117. *)
  118. ;;
  119. esac
  120. }
  121. case "${action}" in
  122. view)
  123. do_view_action "${filetype}"
  124. ;;
  125. open)
  126. "${MC_XDG_OPEN}" "${MC_EXT_FILENAME}" 2>/dev/null || \
  127. do_open_action "${filetype}" "${pager}"
  128. ;;
  129. *)
  130. ;;
  131. esac