aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Bynens <mathias@qiwi.be>2013-05-01 11:12:35 +0200
committerMathias Bynens <mathias@qiwi.be>2013-05-01 16:04:01 +0200
commitb53818ffd84cf53c858492eb879a49a92bf65d27 (patch)
tree5ae867cb27bd048604f178fec0edf5e96930fd44
parentf21a29cd78d65300e6853338864b5c9507f0e1ca (diff)
downloaddotfiles-b53818ffd84cf53c858492eb879a49a92bf65d27.tar.gz
dotfiles-b53818ffd84cf53c858492eb879a49a92bf65d27.tar.bz2
dotfiles-b53818ffd84cf53c858492eb879a49a92bf65d27.zip
.functions: Improve `targz`
* Only use `zopfli` when it’s available and if the `.tar` file is smaller than 50 MB. * Use `pigz` instead of `gzip` when it’s available. * Always exclude `.DS_Store` files when creating a tarball. Closes #199.
-rwxr-xr-x.brew2
-rw-r--r--.functions30
2 files changed, 24 insertions, 8 deletions
diff --git a/.brew b/.brew
index b60e746..b4e0e6d 100755
--- a/.brew
+++ b/.brew
@@ -39,10 +39,12 @@ brew install git
#brew install imagemagick
brew install lynx
brew install node
+brew install pigz
brew install rename
brew install rhino
brew install tree
brew install webkit2png
+brew install zopfli
brew tap homebrew/versions
brew install lua52
diff --git a/.functions b/.functions
index da26384..c16972c 100644
--- a/.functions
+++ b/.functions
@@ -26,18 +26,32 @@ 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
+# Create a .tar.gz archive, using `zopfli`, `pigz` or `gzip` for compression
function targz() {
- if zopfli > /dev/null 2>&1; then
+ local tmpFile="${@}.tar"
+ tar -cvf "${tmpFile}" --exclude=".DS_Store" "${@}" || return 1
+
+ size=$(
+ stat -f"%z" "${tmpFile}" 2> /dev/null; # OS X `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
- cmd="gzip"
+ if hash pigz 2> /dev/null; then
+ cmd="pigz"
+ else
+ cmd="gzip"
+ fi
fi
- local tmpFile="${1}.tar"
- tar -cvf "${tmpFile}" "${1}" &&
- "${cmd}" "${tmpFile}" &&
- rm "${tmpFile}" 2> /dev/null &&
- echo "${tmpFile}.gz created successfully (compressed using \`${cmd}\`)."
+
+ echo "Compressing .tar using \`${cmd}\`…"
+ "${cmd}" -v "${tmpFile}" || return 1
+ [ -f "${tmpFile}" ] && rm "${tmpFile}"
+ echo "${tmpFile}.gz created successfully."
}
# Determine size of a file or total size of a directory