aboutsummaryrefslogtreecommitdiff
path: root/bin/rndf
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-01 10:46:24 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-01 10:46:24 +1200
commitdb2583c7bba896b46c689c16583a42977f0449b0 (patch)
treec24a6c0f2e02bfa21b3c074aa37db6e8196e1362 /bin/rndf
parentChange xrbg(1) to be POSIX sh (diff)
downloaddotfiles-db2583c7bba896b46c689c16583a42977f0449b0.tar.gz
dotfiles-db2583c7bba896b46c689c16583a42977f0449b0.zip
Add rndf(1)
Diffstat (limited to 'bin/rndf')
-rwxr-xr-xbin/rndf11
1 files changed, 11 insertions, 0 deletions
diff --git a/bin/rndf b/bin/rndf
new file mode 100755
index 00000000..fa11e68e
--- /dev/null
+++ b/bin/rndf
@@ -0,0 +1,11 @@
+#!/bin/sh
+# Choose a random file from a given directory. Ignores dot files.
+dir=${1:-.}
+set -- "$dir"/*
+if ! [ -e "$1" ] ; then
+ printf >&2 'rndf: No files found in %s\n' "$dir"
+ exit 1
+fi
+argi=$(rndi 1 "$#") || exit
+shift "$((argi-1))"
+printf '%s\n' "$1"