2018-11-25 04:45:08 +01:00
|
|
|
# vim:et sts=2 sw=2 ft=zsh
|
2015-12-16 23:00:25 +01:00
|
|
|
#
|
|
|
|
# Creates archive files
|
|
|
|
#
|
|
|
|
|
2018-11-15 02:32:37 +01:00
|
|
|
if (( # < 2 )); then
|
2018-11-25 04:45:08 +01:00
|
|
|
print "usage: ${0} <archive_name.ext> <file>..." >&2
|
2016-01-07 21:36:31 +01:00
|
|
|
return 1
|
2015-12-16 23:00:25 +01:00
|
|
|
fi
|
|
|
|
|
2018-11-15 02:32:37 +01:00
|
|
|
# we are quitting (above) if there are less than 2 vars,
|
2015-12-16 23:00:25 +01:00
|
|
|
# so we don't need any argc check here.
|
|
|
|
|
2018-11-25 04:45:08 +01:00
|
|
|
local archive_name="${1}"
|
2018-11-15 02:32:37 +01:00
|
|
|
shift
|
2015-12-16 23:00:25 +01:00
|
|
|
|
2015-12-19 23:08:43 +01:00
|
|
|
# pigz and pbzip2 are aliased in the init.zsh file. This provides a significant speedup, resulting in a
|
|
|
|
# near-liner decrease in compression time based on on the number of available cores.
|
2015-12-16 23:00:25 +01:00
|
|
|
|
|
|
|
case "${archive_name}" in
|
2018-11-15 02:32:37 +01:00
|
|
|
(*.tar.gz|*.tgz) tar -cvzf "${archive_name}" "${@}" ;;
|
|
|
|
(*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar -cvjf "${archive_name}" "${@}" ;;
|
|
|
|
(*.tar.xz|*.txz) tar -J --help &>/dev/null && tar -cvJf "${archive_name}" "${@}" ;;
|
|
|
|
(*.tar.lzma|*.tlz) tar --lzma --help &>/dev/null && tar --lzma -cvf "${archive_name}" "${@}" ;;
|
|
|
|
(*.tar) tar -cvf "${archive_name}" "${@}" ;;
|
|
|
|
(*.zip) zip -r "${archive_name}" "${@}" ;;
|
|
|
|
(*.rar) rar a "${archive_name}" "${@}" ;;
|
|
|
|
(*.7z) 7za a "${archive_name}" "${@}" ;;
|
2015-12-16 23:00:25 +01:00
|
|
|
(*.gz) print "${0}: .gz is only useful for single files, and does not capture permissions. Use .tar.gz" ;;
|
2018-11-06 20:05:12 +01:00
|
|
|
(*.bz|*.bz2) print "${0}: .bzip2 is only useful for single files, and does not capture permissions. Use .tar.bz2" ;;
|
2015-12-16 23:00:25 +01:00
|
|
|
(*.xz) print "${0}: .xz is only useful for single files, and does not capture permissions. Use .tar.xz" ;;
|
|
|
|
(*.lzma) print "${0}: .lzma is only useful for single files, and does not capture permissions. Use .tar.lzma" ;;
|
|
|
|
(*) print "${0}: unknown archive type: ${archive_name}" ;;
|
|
|
|
esac
|