#!/usr/bin/env zsh # # Creates archive file # # Authors: # Matt Hamilton # local archive_name dir_to_archive _gzip_bin _bzip2_bin if (( $# != 2 )); then cat >&2 <&2 return 1 fi # here, we check for dropin/multi-threaded replacements # this should eventually be moved to modules/archive/init.zsh # as a global alias if (( $+commands[pigz] )); then _gzip_bin='pigz' else _gzip_bin='gzip' fi if (( $+commands[pbzip2] )); then _bzip2_bin='pbzip2' else _bzip2_bin='bzip2' fi case "${archive_name}" in (*.tar.gz|*.tgz) tar -cvf "${archive_name}" --use-compress-program="${_gzip_bin}" "${dir_to_archive}" ;; (*.tar.bz2|*.tbz|*.tbz2) tar -cvf "${archive_name}" --use-compress-program="${_bzip2_bin}" "${dir_to_archive}" ;; (*.tar.xz|*.txz) tar -cvJf "${archive_name}" "${dir_to_archive}" ;; (*.tar.lzma|*.tlz) tar -cvf "${archive_name}" --lzma "${dir_to_archive}" ;; (*.tar) tar -cvf "${archive_name}" "${dir_to_archive}" ;; (*.zip|*.jar) zip -r "${archive_name}" "${dir_to_archive}" ;; (*.rar) rar a "${archive_name}" "${dir_to_archive}" ;; (*.7z) 7za a "${archive_name}" "${dir_to_archive}" ;; (*.gz) print "\n.gz is only useful for single files, and does not capture permissions. Use .tar.gz" ;; (*.bz2) print "\n.bzip2 is only useful for single files, and does not capture permissions. Use .tar.bz2" ;; (*.xz) print "\n.xz is only useful for single files, and does not capture permissions. Use .tar.xz" ;; (*.lzma) print "\n.lzma is only useful for single files, and does not capture permissions. Use .tar.lzma" ;; (*) print "\nunknown archive type for archive: ${archive_name}" ;; esac