From eb0f78fc160af9b7d28da975b78b89260cfc0742 Mon Sep 17 00:00:00 2001 From: Nikolas Grottendieck Date: Mon, 10 Apr 2023 19:17:11 +0200 Subject: [PATCH] improve gz function See https://github.com/mathiasbynens/dotfiles/pull/1044 --- stow/shell/dot-functions | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stow/shell/dot-functions b/stow/shell/dot-functions index 07c5796d42..1d885cf5f6 100644 --- a/stow/shell/dot-functions +++ b/stow/shell/dot-functions @@ -85,7 +85,10 @@ function server() { # Compare original and gzipped file size function gz() { local origsize gzipsize ratio - origsize=$(wc -c <"${1}") + origsize=$( + stat -Lf"%z" -- "$1" 2> /dev/null; # macOS `stat` + stat -Lc"%s" -- "$1" 2> /dev/null; # GNU `stat` + ); gzipsize=$(gzip -c "${1}" | wc -c) ratio=$(echo "${gzipsize} * 100 / ${origsize}" | bc -l) printf "orig: %d bytes\n" "${origsize}"