From 71448f5fcd8bc86d86f1f770ed3397caa6d5a92e Mon Sep 17 00:00:00 2001 From: Mathias Bynens Date: Mon, 29 Apr 2013 14:24:36 +0200 Subject: .functions: Add `targz` `targz some-directory` creates `some-directory.tar.gz`, where compression is handled by either `zopfli` (if available) or `gzip`. --- .functions | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to '.functions') diff --git a/.functions b/.functions index 001e3d9..ef25746 100644 --- a/.functions +++ b/.functions @@ -26,6 +26,20 @@ function cdf() { # short for `cdfinder` cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')" } +# Create a .tar.gz archive, using `zopfli` or `gzip` for compression +function targz() { + if zopfli > /dev/null 2>&1; then + cmd="zopfli" + else + cmd="gzip" + fi + local tmpFile="${1}.tar" + tar -cvf "${tmpFile}" "${1}" && + "${cmd}" "${tmpFile}" && + rm "${tmpFile}" && + echo "${tmpFile}.gz created successfully (compressed using \`${cmd}\`)." +} + # Determine size of a file or total size of a directory function fs() { if du -b /dev/null > /dev/null 2>&1; then -- cgit v1.2.3