archive.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. lz)
  22. lzip -dc "${MC_EXT_FILENAME}" 2>/dev/null
  23. ;;
  24. lz4)
  25. lz4 -dc "${MC_EXT_FILENAME}" 2>/dev/null
  26. ;;
  27. lzma)
  28. lzma -dc "${MC_EXT_FILENAME}" 2>/dev/null
  29. ;;
  30. lzo)
  31. lzop -dc "${MC_EXT_FILENAME}" 2>/dev/null
  32. ;;
  33. xz)
  34. xz -dc "${MC_EXT_FILENAME}" 2>/dev/null
  35. ;;
  36. zst)
  37. zstd -dc "${MC_EXT_FILENAME}" 2>/dev/null
  38. ;;
  39. tar)
  40. tar tvvf - < "${MC_EXT_FILENAME}"
  41. ;;
  42. tar.gz|tar.qpr)
  43. gzip -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
  44. tar tvvf -
  45. ;;
  46. tar.bzip)
  47. bzip -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
  48. tar tvvf -
  49. ;;
  50. tar.bzip2)
  51. bzip2 -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
  52. tar tvvf -
  53. ;;
  54. tar.lz)
  55. lzip -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
  56. tar tvvf -
  57. ;;
  58. tar.lz4)
  59. lz4 -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
  60. tar tvvf -
  61. ;;
  62. tar.lzma)
  63. lzma -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
  64. tar tvvf -
  65. ;;
  66. tar.lzo|tzo)
  67. lzop -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
  68. tar tvvf -
  69. ;;
  70. tar.xz)
  71. xz -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
  72. tar tvvf -
  73. ;;
  74. tar.zst|tzst)
  75. zstd -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
  76. tar tvvf -
  77. ;;
  78. tar.F)
  79. freeze -dc "${MC_EXT_FILENAME}" 2>/dev/null | \
  80. tar tvvf -
  81. ;;
  82. lha)
  83. lha l "${MC_EXT_FILENAME}" 2>/dev/null || \
  84. jlha l "${MC_EXT_FILENAME}" 2>/dev/null || \
  85. lhasa l "${MC_EXT_FILENAME}" 2>/dev/null
  86. ;;
  87. arj)
  88. arj l "${MC_EXT_FILENAME}" 2>/dev/null || \
  89. unarj l "${MC_EXT_FILENAME}" 2>/dev/null || \
  90. 7za l "${MC_EXT_FILENAME}" 2>/dev/null
  91. ;;
  92. cab)
  93. cabextract -l "${MC_EXT_FILENAME}" 2> /dev/null || \
  94. 7za l "${MC_EXT_FILENAME}" 2>/dev/null
  95. ;;
  96. ha)
  97. ha lf "${MC_EXT_FILENAME}"
  98. ;;
  99. rar)
  100. rar v -c- "${MC_EXT_FILENAME}" 2>/dev/null || \
  101. unrar v -c- "${MC_EXT_FILENAME}"
  102. ;;
  103. alz)
  104. unalz -l "${MC_EXT_FILENAME}"
  105. ;;
  106. cpio.z|cpio.gz)
  107. gzip -dc "${MC_EXT_FILENAME}" | \
  108. cpio -itv 2>/dev/null
  109. ;;
  110. cpio.lz)
  111. lzip -dc "${MC_EXT_FILENAME}" | \
  112. cpio -itv 2>/dev/null
  113. ;;
  114. cpio.lz4)
  115. lz4 -dc "${MC_EXT_FILENAME}" | \
  116. cpio -itv 2>/dev/null
  117. ;;
  118. cpio.lzo)
  119. lzop -dc "${MC_EXT_FILENAME}" | \
  120. cpio -itv 2>/dev/null
  121. ;;
  122. cpio.xz)
  123. xz -dc "${MC_EXT_FILENAME}" | \
  124. cpio -itv 2>/dev/null
  125. ;;
  126. cpio.zst)
  127. zstd -dc "${MC_EXT_FILENAME}" | \
  128. cpio -itv 2>/dev/null
  129. ;;
  130. cpio)
  131. cpio -itv < "${MC_EXT_FILENAME}" 2>/dev/null
  132. ;;
  133. 7z)
  134. 7za l "${MC_EXT_FILENAME}" 2>/dev/null ||
  135. 7z l "${MC_EXT_FILENAME}"
  136. ;;
  137. ace)
  138. unace l "${MC_EXT_FILENAME}"
  139. ;;
  140. arc)
  141. arc l "${MC_EXT_FILENAME}"
  142. ;;
  143. zip)
  144. unzip -v "${MC_EXT_FILENAME}" 2> /dev/null || \
  145. 7za l "${MC_EXT_FILENAME}" 2> /dev/null
  146. ;;
  147. zipx)
  148. 7za l "${MC_EXT_FILENAME}" 2> /dev/null
  149. ;;
  150. zoo)
  151. zoo l "${MC_EXT_FILENAME}"
  152. ;;
  153. wim)
  154. wimlib-imagex info "${MC_EXT_FILENAME}" 2> /dev/null
  155. ;;
  156. *)
  157. ;;
  158. esac
  159. }
  160. do_open_action() {
  161. filetype=$1
  162. pager=$2
  163. case "${filetype}" in
  164. bzip2)
  165. bzip2 -dc "${MC_EXT_FILENAME}" | ${pager}
  166. ;;
  167. bzip)
  168. bzip -dc "${MC_EXT_FILENAME}" | ${pager}
  169. ;;
  170. gz)
  171. gz -dc "${MC_EXT_FILENAME}" | ${pager}
  172. ;;
  173. lz)
  174. lzip -dc "${MC_EXT_FILENAME}" | ${pager}
  175. ;;
  176. lz4)
  177. lz4 -dc "${MC_EXT_FILENAME}" | ${pager}
  178. ;;
  179. lzma)
  180. lzma -dc "${MC_EXT_FILENAME}" | ${pager}
  181. ;;
  182. lzo)
  183. lzop -dc "${MC_EXT_FILENAME}" | ${pager}
  184. ;;
  185. xz)
  186. xz -dc "${MC_EXT_FILENAME}" | ${pager}
  187. ;;
  188. zst)
  189. zstd -dc "${MC_EXT_FILENAME}" | ${pager}
  190. ;;
  191. par2)
  192. par2 r "${MC_EXT_FILENAME}"
  193. ;;
  194. *)
  195. ;;
  196. esac
  197. }
  198. case "${action}" in
  199. view)
  200. do_view_action "${filetype}"
  201. ;;
  202. open)
  203. ("${MC_XDG_OPEN}" "${MC_EXT_FILENAME}" >/dev/null 2>&1) || \
  204. do_open_action "${filetype}" "${pager}"
  205. ;;
  206. *)
  207. ;;
  208. esac