chemoelectric

lesspipe

Dec 2nd, 2025
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.50 KB | Source Code | 0 0
  1. #!/usr/bin/env nix-shell
  2. #! nix-shell -i zsh -p zsh gzip bzip2 lz4 xz zstd unzip pax --pure
  3.  
  4. file="${1}"
  5.  
  6. function expand
  7. {
  8.     ${2} -dc ${1} 2>/dev/null
  9. }
  10.  
  11. function expand_archive
  12. {
  13.     ${2} -dc ${1} 2>/dev/null | pax -v 2>/dev/null
  14. }
  15.  
  16. case "${1}" in
  17.     *.tar.Z) uncompress -c ${1} 2>/dev/null | pax -v 2>/dev/null ;;
  18.     *.tar.gz) expand_archive "${file}" gzip ;;
  19.     *.tgz) expand_archive "${file}" gzip ;;
  20.     *.tar.bz2) expand_archive "${file}" bzip2 ;;
  21.     *.tar.lz4) expand_archive "${file}" lz4 ;;
  22.     *.tar.xz) expand_archive "${file}" xz ;;
  23.     *.tar.zst) expand_archive "${file}" zstd ;;
  24.  
  25.     *.tar) pax -v -f "${file}" 2>/dev/null ;;
  26.  
  27.     *.cpio.Z) uncompress -c ${1} 2>/dev/null | pax -v 2>/dev/null ;;
  28.     *.cpio.gz) expand_archive "${file}" gzip ;;
  29.     *.tgz) expand_archive "${file}" gzip ;;
  30.     *.cpio.bz2) expand_archive "${file}" bzip2 ;;
  31.     *.cpio.lz4) expand_archive "${file}" lz4 ;;
  32.     *.cpio.xz) expand_archive "${file}" xz ;;
  33.     *.cpio.zst) expand_archive "${file}" zstd ;;
  34.  
  35.     *.cpio) pax -v -f "${file}" 2>/dev/null ;;
  36.  
  37.     *.Z) uncompress -c "${file}"  2>/dev/null ;;
  38.     *.gz) expand "${file}" gzip ;;
  39.     *.bz2) expand "${file}" bzip2 ;;
  40.     *.lz4) expand "${file}" lz4 ;;
  41.     *.xz) expand "${file}" xz ;;
  42.     *.zst) expand "${file}" zstd ;;
  43.  
  44.     *.zip) unzip -l "${file}" 2>/dev/null ;;
  45.     *.ZIP) unzip -l "${file}" 2>/dev/null ;;
  46.  
  47.     *) exit 1 ;;
  48. esac
  49.  
  50. exit $?
  51.  
  52. # local variables:
  53. # mode: shell-script
  54. # sh-shell: zsh
  55. # coding: utf-8
  56. # end:
  57.  
Advertisement
Add Comment
Please, Sign In to add comment