From 1a68b1e968df255b0df0a6a2d3ddf0c66d7bebdc Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Sat, 8 Dec 2012 11:47:28 +0100 Subject: .functions: Make `gz` more awesome --- .functions | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to '.functions') 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. -- cgit v1.2.3