text.sh.in 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/bin/sh
  2. # $1 - action
  3. # $2 - type of archive
  4. # $3 - pager
  5. action=$1
  6. filetype=$2
  7. pager=$3
  8. get_unpacker() {
  9. filetype=$1
  10. case "${filetype}" in
  11. man.gz)
  12. unpacker="gzip -dc"
  13. ;;
  14. man.bz)
  15. unpacker="bzip -dc"
  16. ;;
  17. man.bz2)
  18. unpacker="bzip2 -dc"
  19. ;;
  20. man.lzma)
  21. unpacker="lzma -dc"
  22. ;;
  23. man.xz)
  24. unpacker="xz -dc"
  25. ;;
  26. esac
  27. echo ${unpacker}
  28. }
  29. do_view_action() {
  30. filetype=$1
  31. pager=$2
  32. unpacker=`get_unpacker ${filetype}`
  33. case "${filetype}" in
  34. man)
  35. case "${MC_EXT_CURRENTDIR}"/"${MC_EXT_FILENAME}" in
  36. */log/*|*/logs/*)
  37. cat "${MC_EXT_FILENAME}"
  38. ;;
  39. *)
  40. { zsoelim "${MC_EXT_FILENAME}" 2>/dev/null || cat "${MC_EXT_FILENAME}"; } | nroff @MAN_FLAGS@ @MANDOC@
  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_CURRENTDIR}"/"${MC_EXT_FILENAME}" in
  55. */log/*|*/logs/*)
  56. ${unpacker} %f
  57. ;;
  58. *)
  59. ${unpacker} ${filename} | nroff @MAN_FLAGS@ @MANDOC@
  60. ;;
  61. esac
  62. ;;
  63. *)
  64. ;;
  65. esac
  66. }
  67. do_open_action() {
  68. filetype=$1
  69. pager=$2
  70. unpacker=`get_unpacker ${filetype}`
  71. case "${filetype}" in
  72. info)
  73. info -f "${MC_EXT_FILENAME}"
  74. ;;
  75. man)
  76. case "${MC_EXT_CURRENTDIR}"/"${MC_EXT_FILENAME}" in
  77. */log/*|*/logs/*)
  78. cat "${MC_EXT_FILENAME}"
  79. ;;
  80. *)
  81. { zsoelim "${MC_EXT_FILENAME}" 2>/dev/null || cat "${MC_EXT_FILENAME}"; } | \
  82. nroff @MAN_FLAGS@ @MANDOC@
  83. ;;
  84. esac | ${pager}
  85. ;;
  86. pod)
  87. pod2man "${MC_EXT_FILENAME}" | nroff @MAN_FLAGS@ @MANDOC@ | ${pager}
  88. ;;
  89. nroff.me)
  90. nroff @MAN_FLAGS@ -me "${MC_EXT_FILENAME}" | ${pager}
  91. ;;
  92. nroff.ms)
  93. nroff @MAN_FLAGS@ -ms "${MC_EXT_FILENAME}" | ${pager}
  94. ;;
  95. man.gz|man.bz|man.bz2|man.lzma|man.xz)
  96. case "${MC_EXT_CURRENTDIR}"/"${MC_EXT_FILENAME}" in
  97. */log/*|*/logs/*)
  98. ${unpacker} "${MC_EXT_FILENAME}"
  99. ;;
  100. *)
  101. ${unpacker} "${MC_EXT_FILENAME}" | nroff @MAN_FLAGS@ @MANDOC@
  102. ;;
  103. esac | ${pager}
  104. ;;
  105. chm)
  106. which kchmviewer > /dev/null 2>&1 && (kchmviewer "${MC_EXT_FILENAME}" &) || (xchm "${MC_EXT_FILENAME}" &)
  107. ;;
  108. *)
  109. ;;
  110. esac
  111. }
  112. case "${action}" in
  113. view)
  114. do_view_action "${filetype}" "${pager}"
  115. ;;
  116. open)
  117. xdg-open "${MC_EXT_FILENAME}" 2>/dev/null || \
  118. do_open_action "${filetype}" "${pager}"
  119. ;;
  120. *)
  121. ;;
  122. esac