diff --git a/modules/archive/README.md b/modules/archive/README.md index d5ebaff..d15080a 100644 --- a/modules/archive/README.md +++ b/modules/archive/README.md @@ -9,7 +9,7 @@ Functions --------- * `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 --------------- diff --git a/modules/archive/functions/_unarchive b/modules/archive/functions/_unarchive index 4a8daef..b188308 100644 --- a/modules/archive/functions/_unarchive +++ b/modules/archive/functions/_unarchive @@ -1,4 +1,4 @@ #compdef unarchive _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)(-.)'" diff --git a/modules/archive/functions/unarchive b/modules/archive/functions/unarchive index 8113234..4f10967 100644 --- a/modules/archive/functions/unarchive +++ b/modules/archive/functions/unarchive @@ -3,32 +3,39 @@ # Unarchives files # -if (( # != 1 )); then - print "usage: ${0} " >&2 +if (( # < 1 )); then + print "usage: ${0} ..." >&2 return 1 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. # setting it as an alias in the init.zsh file should be sufficient here. -case "${archive_name}" in - (*.tar.gz|*.tgz) tar -xvzf "${archive_name}" ;; - (*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar -xvjf "${archive_name}" ;; - (*.tar.xz|*.txz) tar -J --help &>/dev/null && tar -xvJf "${archive_name}" \ - || xzcat "${archive_name}" | tar xvf - ;; - (*.tar.lzma|*.tlz) tar --lzma --help &>/dev/null && tar --lzma -xvf "${archive_name}" \ - || lzcat "${archive_name}" | tar xvf - ;; - (*.tar) tar xvf "${archive_name}" ;; - (*.gz) gunzip "${archive_name}" ;; - (*.bz|*.bz2) bunzip2 "${archive_name}" ;; - (*.xz) unxz "${archive_name}" ;; - (*.lzma) unlzma "${archive_name}" ;; - (*.Z) uncompress "${archive_name}" ;; - (*.zip) unzip "${archive_name}";; - (*.rar) (( $+{commands[unrar]} )) && unrar x -ad "${archive_name}" \ - || rar x -ad "${archive_name}" ;; - (*.7z|*.001) 7za x "${archive_name}" ;; - (*) print "${0}: unknown archive type: ${archive_name}" ;; -esac +while (( # > 0 )); do + local archive_name="${1}" + case "${archive_name}" in + (*.tar.gz|*.tgz) tar -xvzf "${archive_name}" ;; + (*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar -xvjf "${archive_name}" ;; + (*.tar.xz|*.txz) tar -J --help &>/dev/null && tar -xvJf "${archive_name}" \ + || xzcat "${archive_name}" | tar xvf - ;; + (*.tar.lzma|*.tlz) tar --lzma --help &>/dev/null && tar --lzma -xvf "${archive_name}" \ + || lzcat "${archive_name}" | tar xvf - ;; + (*.tar) tar xvf "${archive_name}" ;; + (*.gz) gunzip "${archive_name}" ;; + (*.bz|*.bz2) bunzip2 "${archive_name}" ;; + (*.xz) unxz "${archive_name}" ;; + (*.lzma) unlzma "${archive_name}" ;; + (*.Z) uncompress "${archive_name}" ;; + (*.zip) unzip "${archive_name}";; + (*.rar) (( $+{commands[unrar]} )) && unrar x -ad "${archive_name}" \ + || rar x -ad "${archive_name}" ;; + (*.7z|*.001) 7za x "${archive_name}" ;; + (*) + print "${0}: unknown archive type: ${archive_name}" + return 1 + ;; + esac + shift +done