1
0
mirror of https://github.com/dcarrillo/prezto.git synced 2024-12-22 11:38:00 +00:00

utility: Use Zsh native mechanism to detect GNU 'du'

Skip additional call to `grep` and use Zsh native mechanism to detect
GNU version of `du`.

Further, Remove redundant `function` clause as per Prezto convention.
This commit is contained in:
Indrajit Raychaudhuri 2021-05-10 16:34:00 -05:00 committed by Indrajit Raychaudhuri
parent 6eb4021556
commit d3d79bbe74

View File

@ -6,22 +6,22 @@
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
function dut {
(( $# == 0 )) && set -- *
# function dut {
if grep -q -i 'GNU' < <(du --version 2>&1); then
du -khsc "$@" | sort -h -r
else
local line size name
local -a record
(( $# == 0 )) && set -- *
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
fi
}
if [[ ${(@M)${(f)"$(du --version 2>&1)"}:#*GNU *} ]]; then
du -khsc "$@" | sort -h -r
else
local line size name
local -a record
dut "$@"
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
fi
# }