1
0
Fork 0
mirror of synced 2024-12-28 00:43:20 -05:00
zimfw/modules/archive/functions/unarchive

42 lines
1.3 KiB
Text
Raw Normal View History

# vim:et sts=2 sw=2 ft=zsh
2015-12-16 17:00:25 -05:00
#
# Unarchives files
#
if (( # < 1 )); then
print "usage: ${0} <archive_name.ext>..." >&2
2016-01-07 15:36:31 -05:00
return 1
2015-12-16 17:00:25 -05:00
fi
setopt LOCAL_OPTIONS ERR_RETURN
2015-12-16 17:00:25 -05:00
# 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.
2015-12-16 17:00:25 -05:00
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