2015-12-16 23:00:25 +01:00
|
|
|
#
|
|
|
|
# Unarchives files
|
|
|
|
#
|
|
|
|
|
2015-12-19 15:48:29 +01:00
|
|
|
if (( ${#} != 1 )); then
|
2016-01-07 21:36:31 +01:00
|
|
|
print "usage: ${0} [archive.ext]" >&2
|
|
|
|
return 1
|
2015-12-16 23:00:25 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -s ${1} ]]; then
|
|
|
|
print "archive \"${1}\" was not found or has size 0." >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# strip the path, just in case one is provided for some reason
|
2018-02-08 00:27:59 +01:00
|
|
|
local archive_name="${1:t}"
|
2015-12-16 23:00:25 +01:00
|
|
|
|
|
|
|
# using unpigz/pbunzip2 provides little to decompression time; the benefit is mainly in compression time.
|
2015-12-19 23:08:43 +01:00
|
|
|
# setting it as an alias in the init.zsh file should be sufficient here.
|
2015-12-16 23:00:25 +01:00
|
|
|
|
|
|
|
case "${archive_name}" in
|
|
|
|
(*.tar.gz|*.tgz) tar -xvzf "${archive_name}" ;;
|
|
|
|
(*.tar.bz2|*.tbz|*.tbz2) tar -xvjf "${archive_name}" ;;
|
2018-02-08 00:27:59 +01:00
|
|
|
(*.tar.xz|*.txz) tar --xz --help &>/dev/null && tar --xz -xvf "${archive_name}" \
|
2015-12-16 23:00:25 +01:00
|
|
|
|| xzcat "${archive_name}" | tar xvf - ;;
|
2018-02-08 17:03:30 +01:00
|
|
|
(*.tar.lzma|*.tlz) tar --lzma --help &>/dev/null && tar --lzma -xvf "${archive_name}" \
|
2015-12-16 23:00:25 +01:00
|
|
|
|| lzcat "${archive_name}" | tar xvf - ;;
|
|
|
|
(*.tar) tar xvf "${archive_name}" ;;
|
|
|
|
(*.gz) gunzip "${archive_name}" ;;
|
|
|
|
(*.bz2) bunzip2 "${archive_name}" ;;
|
|
|
|
(*.xz) unxz "${archive_name}" ;;
|
|
|
|
(*.lzma) unlzma "${archive_name}" ;;
|
|
|
|
(*.Z) uncompress "${archive_name}" ;;
|
2015-12-17 20:04:33 +01:00
|
|
|
(*.zip) unzip "${archive_name}";;
|
2018-02-08 00:27:59 +01:00
|
|
|
(*.rar) (( $+{commands[unrar]} )) && unrar x -ad "${archive_name}" \
|
2015-12-16 23:00:25 +01:00
|
|
|
|| rar x -ad "${archive_name}" ;;
|
2017-10-14 17:28:03 +02:00
|
|
|
(*.7z|*.001) 7za x "${archive_name}" ;;
|
2015-12-16 23:00:25 +01:00
|
|
|
(*) print "${0}: unknown archive type: ${archive_name}" ;;
|
|
|
|
esac
|