aboutsummaryrefslogtreecommitdiff
path: root/bin/dub.sh
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-04-05 20:06:39 +1200
committerTom Ryder <tom@sanctum.geek.nz>2017-04-05 20:46:47 +1200
commitc8ab406749124d2e762ad5cf53963070113afd0f (patch)
tree54c9721a06957ebe7098a211eea803b0230c0f5d /bin/dub.sh
parentHandle POSIX correctness in ~/.bash_profile (diff)
downloaddotfiles-c8ab406749124d2e762ad5cf53963070113afd0f.tar.gz
dotfiles-c8ab406749124d2e762ad5cf53963070113afd0f.zip
Apply runtime shebanging to POSIX shell
Diffstat (limited to 'bin/dub.sh')
-rw-r--r--bin/dub.sh31
1 files changed, 31 insertions, 0 deletions
diff --git a/bin/dub.sh b/bin/dub.sh
new file mode 100644
index 00000000..f42c5ac9
--- /dev/null
+++ b/bin/dub.sh
@@ -0,0 +1,31 @@
+# List the biggest files in a directory
+
+# 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 -k1,1nr |
+
+# Limit the output to the given number of lines
+sed "$lines"q