aboutsummaryrefslogtreecommitdiffstats
path: root/.functions
diff options
context:
space:
mode:
authorNicolas Gallagher <nicolasgallagher@gmail.com>2012-12-08 11:47:28 +0100
committerMathias Bynens <mathias@qiwi.be>2012-12-08 11:48:05 +0100
commit1a68b1e968df255b0df0a6a2d3ddf0c66d7bebdc (patch)
tree3d1187ffa9290fadaf974433aa93231a134c10e5 /.functions
parent5400992ced5746627b9cfec9df08a93318822acc (diff)
downloaddotfiles-1a68b1e968df255b0df0a6a2d3ddf0c66d7bebdc.tar.gz
dotfiles-1a68b1e968df255b0df0a6a2d3ddf0c66d7bebdc.tar.bz2
dotfiles-1a68b1e968df255b0df0a6a2d3ddf0c66d7bebdc.zip
.functions: Make `gz` more awesome
Diffstat (limited to '.functions')
-rw-r--r--.functions11
1 files changed, 6 insertions, 5 deletions
diff --git a/.functions b/.functions
index 93356f9..c2c1556 100644
--- a/.functions
+++ b/.functions
@@ -52,12 +52,13 @@ function phpserver() {
php -S "${ip}:${port}"
}
-# Get gzipped file size
+# Compare original and gzipped file size
function gz() {
- echo "orig size (bytes): "
- cat "$1" | wc -c
- echo "gzipped size (bytes): "
- gzip -c "$1" | wc -c
+ local origsize=$(wc -c < "$1")
+ local gzipsize=$(gzip -c "$1" | wc -c)
+ local ratio=$(echo "$gzipsize * 100/ $origsize" | bc -l)
+ printf "orig: %d bytes\n" "$origsize"
+ printf "gzip: %d bytes (%2.2f%%)\n" "$gzipsize" "$ratio"
}
# Test if HTTP compression (RFC 2616 + SDCH) is enabled for a given URL.