aboutsummaryrefslogtreecommitdiff
path: root/bin/rndf.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/rndf.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/rndf.sh')
-rw-r--r--bin/rndf.sh17
1 files changed, 17 insertions, 0 deletions
diff --git a/bin/rndf.sh b/bin/rndf.sh
new file mode 100644
index 00000000..21aa76a6
--- /dev/null
+++ b/bin/rndf.sh
@@ -0,0 +1,17 @@
+# Choose a random file from a given directory using rnda(1df); 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 "$@"