archive.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #!/bin/sh
  2. # $1 - action
  3. # $2 - type of file
  4. # $3 - pager
  5. action=$1
  6. filetype=$2
  7. pager=$3
  8. [ -n "${MC_XDG_OPEN}" ] || MC_XDG_OPEN="xdg-open"
  9. do_view_action() {
  10. filetype=$1
  11. case "${filetype}" in
  12. gz)
  13. gzip -dc "${MC_EXT_FILENAME}" 2>/dev/null
  14. ;;
  15. bz2)
  16. bzip2 -dc "${MC_EXT_FILENAME}" 2>/dev/null
  17. ;;
  18. bzip)
  19. bzip2 -dc "${MC_EXT_FILENAME}" 2>/dev/null
  20. ;;
  21. lzma)
  22. lzma -dc "${MC_EXT_FILENAME}" 2>/dev/null
  23. ;;
  24. xz)
  25. xz -dc "${MC_EXT_FILENAME}" 2>/dev/null
  26. ;;
  27. tar)
  28. tar tvvf - < "${MC_EXT_FILENAME}"
  29. ;;
  30. tar.gz|tar.qpr)
  31. gzip -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
  32. tar tvvf -
  33. ;;
  34. tar.bzip)
  35. bzip -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
  36. tar tvvf -
  37. ;;
  38. tar.bzip2)
  39. bzip2 -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
  40. tar tvvf -
  41. ;;
  42. tar.lzma)
  43. lzma -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
  44. tar tvvf -
  45. ;;
  46. tar.xz)
  47. xz -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
  48. tar tvvf -
  49. ;;
  50. tar.F)
  51. freeze -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
  52. tar tvvf -
  53. ;;
  54. lha)
  55. lha l "${MC_EXT_FILENAME}"
  56. ;;
  57. arj)
  58. arj l "${MC_EXT_FILENAME}" 2>/dev/null || \
  59. unarj l "${MC_EXT_FILENAME}"
  60. ;;
  61. cab)
  62. cabextract -l "${MC_EXT_FILENAME}"
  63. ;;
  64. ha)
  65. ha lf "${MC_EXT_FILENAME}"
  66. ;;
  67. rar)
  68. rar v -c- "${MC_EXT_FILENAME}" 2>/dev/null || \
  69. unrar v -c- "${MC_EXT_FILENAME}"
  70. ;;
  71. alz)
  72. unalz -l "${MC_EXT_FILENAME}"
  73. ;;
  74. cpio.z|cpio.gz)
  75. gzip -dc "${MC_EXT_FILENAME}" | \
  76. cpio -itv 2>/dev/null
  77. ;;
  78. cpio.xz)
  79. xz -dc "${MC_EXT_FILENAME}" | \
  80. cpio -itv 2>/dev/null
  81. ;;
  82. cpio)
  83. cpio -itv < "${MC_EXT_FILENAME}" 2>/dev/null
  84. ;;
  85. 7z)
  86. 7za l "${MC_EXT_FILENAME}" 2>/dev/null ||
  87. 7z l "${MC_EXT_FILENAME}"
  88. ;;
  89. ace)
  90. unace l "${MC_EXT_FILENAME}"
  91. ;;
  92. arc)
  93. arc l "${MC_EXT_FILENAME}"
  94. ;;
  95. zip)
  96. unzip -v "${MC_EXT_FILENAME}"
  97. ;;
  98. zoo)
  99. zoo l "${MC_EXT_FILENAME}"
  100. ;;
  101. *)
  102. ;;
  103. esac
  104. }
  105. do_open_action() {
  106. filetype=$1
  107. pager=$2
  108. case "${filetype}" in
  109. bzip2)
  110. bzip2 -dc "${MC_EXT_FILENAME}" | ${pager}
  111. ;;
  112. bzip)
  113. bzip -dc "${MC_EXT_FILENAME}" | ${pager}
  114. ;;
  115. gz)
  116. gz -dc "${MC_EXT_FILENAME}" | ${pager}
  117. ;;
  118. lzma)
  119. lzma -dc "${MC_EXT_FILENAME}" | ${pager}
  120. ;;
  121. xz)
  122. xz -dc "${MC_EXT_FILENAME}" | ${pager}
  123. ;;
  124. par2)
  125. par2 r "${MC_EXT_FILENAME}"
  126. ;;
  127. *)
  128. ;;
  129. esac
  130. }
  131. case "${action}" in
  132. view)
  133. do_view_action "${filetype}"
  134. ;;
  135. open)
  136. "${MC_XDG_OPEN}" "${MC_EXT_FILENAME}" 2>/dev/null || \
  137. do_open_action "${filetype}" "${pager}"
  138. ;;
  139. *)
  140. ;;
  141. esac