Browse Source

Add support for zstd compressed tarballs to module 'archive'

master
Poscat 4 years ago committed by Jeff Widman
parent
commit
03dce24639
  1. 2
      modules/archive/functions/_lsarchive
  2. 2
      modules/archive/functions/_unarchive
  3. 7
      modules/archive/functions/archive
  4. 1
      modules/archive/functions/lsarchive
  5. 5
      modules/archive/functions/unarchive

2
modules/archive/functions/_lsarchive

@ -10,4 +10,4 @@ @@ -10,4 +10,4 @@
_arguments \
'(-v --verbose)'{-v,--remove}'[verbose archive listing]' \
"*::archive file:_files -g '(#i)*.(tar|tgz|tbz|tbz2|txz|tlz|gz|bz2|xz|lzma|Z|zip|jar|rar|7z)(-.)'" && return 0
"*::archive file:_files -g '(#i)*.(tar|tgz|tbz|tbz2|txz|tlz|gz|bz2|xz|lzma|Z|zip|zst|jar|rar|7z)(-.)'" && return 0

2
modules/archive/functions/_unarchive

@ -10,4 +10,4 @@ @@ -10,4 +10,4 @@
_arguments \
'(-r --remove)'{-r,--remove}'[remove archive]' \
"*::archive file:_files -g '(#i)*.(tar|tgz|tbz|tbz2|txz|tlz|gz|bz2|xz|lzma|Z|zip|jar|rar|7z|deb)(-.)'" && return 0
"*::archive file:_files -g '(#i)*.(tar|tgz|tbz|tbz2|txz|tlz|gz|bz2|xz|lzma|Z|zip|zst|jar|rar|7z|deb)(-.)'" && return 0

7
modules/archive/functions/archive

@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
# function archive {
local archive_name path_to_archive _gzip_bin _bzip2_bin _xz_bin
local archive_name path_to_archive _gzip_bin _bzip2_bin _xz_bin _zstd_bin
if (( $# < 2 )); then
cat >&2 <<EOF
@ -16,7 +16,7 @@ usage: $0 [archive_name.zip] [/path/to/include/into/archive ...] @@ -16,7 +16,7 @@ usage: $0 [archive_name.zip] [/path/to/include/into/archive ...]
Where 'archive.zip' uses any of the following extensions:
.tar.gz, .tar.bz2, .tar.xz, .tar.lzma, .tar, .zip, .rar, .7z
.tar.gz, .tar.bz2, .tar.xz, .tar.lzma, .tar.zst, .tar, .zip, .rar, .7z
There is no '-v' switch; all operations are verbose.
EOF
@ -54,11 +54,14 @@ else @@ -54,11 +54,14 @@ else
_bzip2_bin='bzip2'
fi
_zstd_bin='zstd'
case "${archive_name}" in
(*.tar.gz|*.tgz) tar -cvf "${archive_name}" --use-compress-program="${_gzip_bin}" "${=path_to_archive}" ;;
(*.tar.bz2|*.tbz|*.tbz2) tar -cvf "${archive_name}" --use-compress-program="${_bzip2_bin}" "${=path_to_archive}" ;;
(*.tar.xz|*.txz) tar -cvf "${archive_name}" --use-compress-program="${_xz_bin}" "${=path_to_archive}" ;;
(*.tar.lzma|*.tlz) tar -cvf "${archive_name}" --lzma "${=path_to_archive}" ;;
(*.tar.zst|*.tzst) tar -cvf "${archive_name}" --use-compress-program="${_zstd_bin}" "${=path_to_archive}" ;;
(*.tar) tar -cvf "${archive_name}" "${=path_to_archive}" ;;
(*.zip|*.jar) zip -r "${archive_name}" "${=path_to_archive}" ;;
(*.rar) rar a "${archive_name}" "${=path_to_archive}" ;;

1
modules/archive/functions/lsarchive

@ -41,6 +41,7 @@ while (( $# > 0 )); do @@ -41,6 +41,7 @@ while (( $# > 0 )); do
(*.tar.zma|*.tlz) tar --lzma --help &> /dev/null \
&& tar --lzma -t${verbose:+v}f "$1" \
|| lzcat "$1" | tar x${verbose:+v}f - ;;
(*.tar.zst|*.tzst) tar -I zstd -t${verbose:+v}f "$1" ;;
(*.tar) tar t${verbose:+v}f "$1" ;;
(*.zip|*.jar) unzip -l${verbose:+v} "$1" ;;
(*.rar) ( (( $+commands[unrar] )) \

5
modules/archive/functions/unarchive

@ -12,7 +12,7 @@ local success @@ -12,7 +12,7 @@ local success
local file_name
local file_path
local extract_dir
local _gzip_bin _bzip2_bin _xz_bin
local _gzip_bin _bzip2_bin _xz_bin _zstd_bin
if (( $# == 0 )); then
cat >&2 <<EOF
@ -54,6 +54,8 @@ else @@ -54,6 +54,8 @@ else
_bzip2_bin='bzip2'
fi
_zstd_bin='zstd'
while (( $# > 0 )); do
if [[ ! -s "$1" ]]; then
print "$0: file not valid: $1" >&2
@ -72,6 +74,7 @@ while (( $# > 0 )); do @@ -72,6 +74,7 @@ while (( $# > 0 )); do
(*.tar.zma|*.tlz) tar --lzma --help &> /dev/null \
&& tar --lzma -xvf "$1" \
|| lzcat "$1" | tar -xvf - ;;
(*.tar.zst|*.tzst) tar -xvf "$1" --use-compress-program="${_zstd_bin}" ;;
(*.tar) tar -xvf "$1" ;;
(*.gz) gunzip "$1" ;;
(*.bz2) bunzip2 "$1" ;;

Loading…
Cancel
Save