This does not work correctly on systems where the decimal separator is not a "." since bc does not respect LC_NUMERIC, leading to lots of “-bash: printf: xxx.xx: invalid number” error messages.
I hacked it by adding export LC_ALL=C to __sizeup_humanize()
I'm using awk now which properly supports locales:
__sizeup_humanize () {
local size=$1
if [ $size -ge 1073741824 ]; then
echo $size | awk '{printf "%6.2fG \n", $1/1073741824}'
elif [ $size -ge 1048576 ]; then
echo $size | awk '{printf "%6.2fM \n", $1/1048576}'
elif [ $size -ge 1024 ]; then
echo $size | awk '{printf "%6.2fK \n", $1/1024}'
else
printf '%6.2f%s' ${size} b
fi
}
I had a few problems running this in Cygwin, which no one should need to do, and I went and did something. It's not pretty, but it works for me in Cygwin (haven't tested in another terminal yet). I tried to get a one-liner to redefine $size if OS is win or /usr/bin/cygdrive exists, which both indicate bash in Cygwin, but it wouldn't take and I kept getting errors "stat: cannot read file system information for ‘%z’: No such file or directory" for the original $size command.
...shift $((OPTIND-1))
[ ! -x "/usr/bin/bc" ] && echo -e "You need bc installed for the sizing your ups." && return # because you do and I didn't
#local cmd="find . -type f ${depth}$(__sizeup_build_query $@)" # returned error "find: warning: you have specified the -maxdepth option after a non-option argument -type, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments."
local cmd="find . ${depth} -type f $(__sizeup_build_query $@)"
local counter=0
while read -r file; do
counter=$(( $counter+1 ))
if [[ $OS == Windows_NT ]]; then size=$(stat -c '%s' "$file"); # for cygwin
else size=$(stat -f '%z' "$file"); fi # for not cygwin
totalb=$(( $totalb+$size ))...