aboutsummaryrefslogtreecommitdiff
path: root/bin/rndf
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-09 17:15:40 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-09 17:20:10 +1200
commit9fb350dc7c8cc5259ef24e0cb097031179fab1d6 (patch)
tree839dd0b8ee3f5323b1cd6aefa22b605b99437d62 /bin/rndf
parentMention nosls/sls flags in slsf(1) man page (diff)
downloaddotfiles-9fb350dc7c8cc5259ef24e0cb097031179fab1d6.tar.gz
dotfiles-9fb350dc7c8cc5259ef24e0cb097031179fab1d6.zip
Improve commenting/exit handling in binscripts
Diffstat (limited to 'bin/rndf')
-rwxr-xr-xbin/rndf10
1 files changed, 9 insertions, 1 deletions
diff --git a/bin/rndf b/bin/rndf
index 6918dbea..06e15fbe 100755
--- a/bin/rndf
+++ b/bin/rndf
@@ -1,9 +1,17 @@
#!/bin/sh
-# Choose a random file from a given directory using rnda(1). Ignores dot files.
+# Choose a random file from a given directory using rnda(1); ignores dot files
+
+# Directory is first argument; defaults to current directory
dir=${1:-.}
+
+# Set the positional parameters to all the non-dotfiles in that directory
set -- "$dir"/*
+
+# Check for an unexpanded glob (empty directory)
if ! [ -e "$1" ] ; then
printf >&2 'rndf: No files found in %s\n' "$dir"
exit 1
fi
+
+# Print a random argument from the current positional parameters
rnda "$@"