#!/usr/bin/env bash function targz() { DNOW=$( date '+%F-%H-%M') local tmpFile="${@%/}-${DNOW}.tar"; tar -cvf "${tmpFile}" --exclude-vcs-ignores --exclude-vcs --exclude-backups --exclude-caches --exclude=".DS_Store" --exclude="node_modules" --exclude=".idea" "${@}" || return 1; size=$( stat -f"%z" "${tmpFile}" 2> /dev/null; # macOS `stat` stat -c"%s" "${tmpFile}" 2> /dev/null; # GNU `stat` ); local cmd=""; if (( size < 52428800 )) && hash zopfli 2> /dev/null; then # the .tar file is smaller than 50 MB and Zopfli is available; use it cmd="zopfli"; else if hash pigz 2> /dev/null; then cmd="pigz"; else cmd="gzip"; fi; fi; echo "Compressing .tar ($((size / 1000)) kB) using \`${cmd}\`…"; "${cmd}" -v "${tmpFile}" || return 1; [ -f "${tmpFile}" ] && rm "${tmpFile}"; zippedSize=$( stat -f"%z" "${tmpFile}.gz" 2> /dev/null; # macOS `stat` stat -c"%s" "${tmpFile}.gz" 2> /dev/null; # GNU `stat` ); echo "${tmpFile}.gz ($((zippedSize / 1000)) kB) created successfully."; } targz db/menu.db