prezto_config/modules/utility/functions/duh

30 lines
566 B
Plaintext
Raw Normal View History

2012-02-01 05:37:51 +01:00
#
# Displays human readable disk usage.
#
# Authors:
# Suraj N. Kurapati <sunaku@gmail.com>
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
function duh {
2011-10-12 05:13:58 +02:00
(( $# == 0 )) && set -- *
2012-05-21 22:24:39 +02:00
if grep -q -i 'GNU' < <(du --version 2>&1); then
2011-10-12 05:13:58 +02:00
du -khsc "$@" | sort -h -r
else
2012-05-19 18:05:42 +02:00
local line size name
local -a record
2012-05-21 22:24:39 +02:00
2012-05-19 18:05:42 +02:00
while IFS=$'\n' read line; do
record=(${(z)line})
size="$(($record[1] / 1024.0))"
name="$record[2,-1]"
printf "%9.1LfM %s\n" "$size" "$name"
done < <(du -kcs "$@") | sort -n -r
2011-10-12 05:13:58 +02:00
fi
}
compdef _du duh
duh "$@"