From 8ea33ed07aee3f9e6ceb596f1198151bf55e5903 Mon Sep 17 00:00:00 2001 From: Indrajit Raychaudhuri Date: Mon, 10 May 2021 16:34:00 -0500 Subject: [PATCH] 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. --- modules/utility/functions/dut | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/utility/functions/dut b/modules/utility/functions/dut index 6592280..1474197 100644 --- a/modules/utility/functions/dut +++ b/modules/utility/functions/dut @@ -6,22 +6,22 @@ # Sorin Ionescu # -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 + +# }