Browse Source

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.
master
Indrajit Raychaudhuri 4 years ago committed by Indrajit Raychaudhuri
parent
commit
8ea33ed07a
  1. 32
      modules/utility/functions/dut

32
modules/utility/functions/dut

@ -6,22 +6,22 @@
# Sorin Ionescu <sorin.ionescu@gmail.com> # Sorin Ionescu <sorin.ionescu@gmail.com>
# #
function dut { # function dut {
(( $# == 0 )) && set -- *
if grep -q -i 'GNU' < <(du --version 2>&1); then (( $# == 0 )) && set -- *
du -khsc "$@" | sort -h -r
else
local line size name
local -a record
while IFS=$'\n' read line; do if [[ ${(@M)${(f)"$(du --version 2>&1)"}:#*GNU *} ]]; then
record=(${(z)line}) du -khsc "$@" | sort -h -r
size="$(($record[1] / 1024.0))" else
name="$record[2,-1]" local line size name
printf "%9.1LfM %s\n" "$size" "$name" local -a record
done < <(du -kcs "$@") | sort -n -r
fi
}
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
# }

Loading…
Cancel
Save