From 9fb350dc7c8cc5259ef24e0cb097031179fab1d6 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 9 Aug 2016 17:15:40 +1200 Subject: Improve commenting/exit handling in binscripts --- bin/dub | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'bin/dub') diff --git a/bin/dub b/bin/dub index 706c95f0..555bed67 100755 --- a/bin/dub +++ b/bin/dub @@ -1,13 +1,32 @@ #!/bin/sh # List the biggest files in a directory -dir=$1 lines=${2:-10} + +# First optional argument is the directory, defaulting to the +# current dir; second optional argument is the number of files to +# show, defaulting to 20 +dir=${1:-.} lines=${2:-10} + +# Enter the target dir or bail cd -- "$dir" || exit + +# Add files matching glob, shift them off if unexpanded (first and +# only entry doesn't exist) set -- * [ -e "$1" ] || shift + +# Add dot files, shift off the "." and ".." entries (sh(1) +# implementations seem to vary on whether they include these) set -- .* "$@" [ -e "$1" ] || shift [ "$1" = . ] && shift [ "$1" = .. ] && shift + +# Run du(1) with POSIX compatible flags -k for kilobyte unit and +# -s for total over the arguments du -ks -- "$@" | + +# Sort the first field (the sizes) numerically, in reverse sort -k1nr | + +# Limit the output to the given number of lines sed "$lines"q -- cgit v1.2.3