[archive] Support unarchive of multiple files
so we can do `unarchive *.tar.gz` for example. Update README and compdef accordingly.
This commit is contained in:
parent
1e3cee4715
commit
2004fb320b
3 changed files with 31 additions and 24 deletions
|
@ -9,7 +9,7 @@ Functions
|
||||||
---------
|
---------
|
||||||
|
|
||||||
* `archive` generates an archive based on file extension. Syntax is `archive myarchive.tar.gz /path/to/archive`
|
* `archive` generates an archive based on file extension. Syntax is `archive myarchive.tar.gz /path/to/archive`
|
||||||
* `unarchive` unarchives a file based on the extension. Syntax is `unarchive myarchive.7z`
|
* `unarchive` unarchives files based on the extensions. Syntax is `unarchive myarchive.7z`
|
||||||
|
|
||||||
Archive formats
|
Archive formats
|
||||||
---------------
|
---------------
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#compdef unarchive
|
#compdef unarchive
|
||||||
|
|
||||||
_arguments \
|
_arguments \
|
||||||
":archive:_files -g '(#i)*.(tar|gz|tgz|bz2|tbz|tbz2|xz|txz|tlz|lzma|Z|zip|rar|7z|001)(-.)'"
|
"*:archive:_files -g '(#i)*.(tar|gz|tgz|bz|bz2|tbz|tbz2|xz|txz|tlz|lzma|Z|zip|rar|7z|001)(-.)'"
|
||||||
|
|
|
@ -3,16 +3,18 @@
|
||||||
# Unarchives files
|
# Unarchives files
|
||||||
#
|
#
|
||||||
|
|
||||||
if (( # != 1 )); then
|
if (( # < 1 )); then
|
||||||
print "usage: ${0} <archive_name.ext>" >&2
|
print "usage: ${0} <archive_name.ext>..." >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local archive_name="${1}"
|
setopt LOCAL_OPTIONS ERR_RETURN
|
||||||
|
|
||||||
# using unpigz/pbunzip2 provides little to decompression time; the benefit is mainly in compression time.
|
# using unpigz/pbunzip2 provides little to decompression time; the benefit is mainly in compression time.
|
||||||
# setting it as an alias in the init.zsh file should be sufficient here.
|
# setting it as an alias in the init.zsh file should be sufficient here.
|
||||||
|
|
||||||
|
while (( # > 0 )); do
|
||||||
|
local archive_name="${1}"
|
||||||
case "${archive_name}" in
|
case "${archive_name}" in
|
||||||
(*.tar.gz|*.tgz) tar -xvzf "${archive_name}" ;;
|
(*.tar.gz|*.tgz) tar -xvzf "${archive_name}" ;;
|
||||||
(*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar -xvjf "${archive_name}" ;;
|
(*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar -xvjf "${archive_name}" ;;
|
||||||
|
@ -30,5 +32,10 @@ case "${archive_name}" in
|
||||||
(*.rar) (( $+{commands[unrar]} )) && unrar x -ad "${archive_name}" \
|
(*.rar) (( $+{commands[unrar]} )) && unrar x -ad "${archive_name}" \
|
||||||
|| rar x -ad "${archive_name}" ;;
|
|| rar x -ad "${archive_name}" ;;
|
||||||
(*.7z|*.001) 7za x "${archive_name}" ;;
|
(*.7z|*.001) 7za x "${archive_name}" ;;
|
||||||
(*) print "${0}: unknown archive type: ${archive_name}" ;;
|
(*)
|
||||||
|
print "${0}: unknown archive type: ${archive_name}"
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
Loading…
Reference in a new issue