2018-11-24 22:45:08 -05:00
|
|
|
# vim:et sts=2 sw=2 ft=zsh
|
2015-12-16 17:00:25 -05:00
|
|
|
#
|
|
|
|
# Unarchives files
|
|
|
|
#
|
|
|
|
|
2018-11-14 20:32:37 -05:00
|
|
|
if (( # != 1 )); then
|
2018-11-24 22:45:08 -05:00
|
|
|
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
|
|
|
|
|
2018-11-24 22:45:08 -05:00
|
|
|
local archive_name="${1}"
|
2015-12-16 17:00:25 -05:00
|
|
|
|
|
|
|
# using unpigz/pbunzip2 provides little to decompression time; the benefit is mainly in compression time.
|
2015-12-19 17:08:43 -05:00
|
|
|
# setting it as an alias in the init.zsh file should be sufficient here.
|
2015-12-16 17:00:25 -05:00
|
|
|
|
|
|
|
case "${archive_name}" in
|
|
|
|
(*.tar.gz|*.tgz) tar -xvzf "${archive_name}" ;;
|
2018-11-06 14:05:12 -05:00
|
|
|
(*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar -xvjf "${archive_name}" ;;
|
2018-11-14 20:32:37 -05:00
|
|
|
(*.tar.xz|*.txz) tar -J --help &>/dev/null && tar -xvJf "${archive_name}" \
|
2015-12-16 17:00:25 -05:00
|
|
|
|| xzcat "${archive_name}" | tar xvf - ;;
|
2018-02-08 11:03:30 -05:00
|
|
|
(*.tar.lzma|*.tlz) tar --lzma --help &>/dev/null && tar --lzma -xvf "${archive_name}" \
|
2015-12-16 17:00:25 -05:00
|
|
|
|| lzcat "${archive_name}" | tar xvf - ;;
|
|
|
|
(*.tar) tar xvf "${archive_name}" ;;
|
|
|
|
(*.gz) gunzip "${archive_name}" ;;
|
2018-11-06 14:05:12 -05:00
|
|
|
(*.bz|*.bz2) bunzip2 "${archive_name}" ;;
|
2015-12-16 17:00:25 -05:00
|
|
|
(*.xz) unxz "${archive_name}" ;;
|
|
|
|
(*.lzma) unlzma "${archive_name}" ;;
|
|
|
|
(*.Z) uncompress "${archive_name}" ;;
|
2015-12-17 14:04:33 -05:00
|
|
|
(*.zip) unzip "${archive_name}";;
|
2018-02-07 18:27:59 -05:00
|
|
|
(*.rar) (( $+{commands[unrar]} )) && unrar x -ad "${archive_name}" \
|
2015-12-16 17:00:25 -05:00
|
|
|
|| rar x -ad "${archive_name}" ;;
|
2017-10-14 11:28:03 -04:00
|
|
|
(*.7z|*.001) 7za x "${archive_name}" ;;
|
2015-12-16 17:00:25 -05:00
|
|
|
(*) print "${0}: unknown archive type: ${archive_name}" ;;
|
|
|
|
esac
|