From fad5ce7df94056408332c4971ced2c41e5482817 Mon Sep 17 00:00:00 2001 From: q Date: Sat, 20 Oct 2018 14:03:02 +0300 Subject: [PATCH] add format mode only --- files/fastdu | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/files/fastdu b/files/fastdu index 31d24bc..d99b214 100755 --- a/files/fastdu +++ b/files/fastdu @@ -7,6 +7,7 @@ function helpexit() { echo " -s Summary mode, otherwise each argument folder calculated separate" echo " -c Count files instead of summarizing sizes" echo " -a Display animation while counting" + echo " -f # Format filesize to human readable. Command exits without scanning." echo " --help This help" exit } @@ -83,14 +84,25 @@ function displaysize() { # Get options what=() for (( i=1; i<=$#; i++ )); do + [[ "${!i}" = "-a" ]] && { ANIMATE=1; continue; } + [[ "${!i}" = "-f" ]] && { FORMAT=1; ((i++)); FORMAT_VALUE=${!i}; continue; } [[ "${!i}" = "--help" ]] && helpexit [[ "${!i}" = "-h" ]] && { HUMAN=1; continue; } [[ "${!i}" = "-c" ]] && { COUNT=1; continue; } [[ "${!i}" = "-s" ]] && { SUMMARY=1; continue; } - [[ "${!i}" = "-a" ]] && { ANIMATE=1; continue; } what+=( "${!i}" ) done [[ -z "${what[@]}" ]] && what="." +# If formatting requested, do only that: +if [[ "$FORMAT" -eq 1 ]]; then + if [[ -z "$FORMAT_VALUE" ]]; then + echo -e "\nBytes argument missing\n\n" + helpexit + fi + filesize $FORMAT_VALUE + exit $? +fi + # If only one entry, dont print the name [[ "${#what[@]}" -eq 1 ]] && SUMMARY=1