Topic: https://brettterpstra.com/2015/01/05/sizeup-tidy-filesize-information-in-terminal/
hide preview

What's next? verify your email address for reply notifications!

Niklas Bölter 10y, 70d ago

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()

remark link
hide preview

What's next? verify your email address for reply notifications!

Niklas Bölter 10y, 69d ago

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
}

hide preview

What's next? verify your email address for reply notifications!

Bernd Goldschmidt 10y, 71d ago

I get error messages for every file over 1k:

-bash: printf: 24.96: invalid number2 (26175832)

on OS X Yosemite.

hide preview

What's next? verify your email address for reply notifications!

chrismetcalf 10y, 74d ago

Anybody get this working with ZSH?

remark link
hide preview

What's next? verify your email address for reply notifications!

ttscoff 10y, 74d ago

Wish I was more adept with zsh, but if anybody does have a version that works, let me know and I'll append.

remark link parent
hide preview

What's next? verify your email address for reply notifications!

Matt Shelton 10y, 73d ago

Works as-is. I did this:

1. Saved as ~/bin/sizeup.bash
2. Added 'source /Users/myusernamehere/bin/sizeup.bash' to my ~/.zshrc

Log out/in.

hide preview

What's next? verify your email address for reply notifications!

jth 10y, 74d ago

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 ))...
hide preview

What's next? verify your email address for reply notifications!