aboutsummaryrefslogtreecommitdiff
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
parentChange xrbg(1) to be POSIX sh (diff)
downloaddotfiles-db2583c7bba896b46c689c16583a42977f0449b0.tar.gz
dotfiles-db2583c7bba896b46c689c16583a42977f0449b0.zip
Add rndf(1)
-rwxr-xr-xbin/rndf11
-rw-r--r--man/man1/rndf.119
2 files changed, 30 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"
diff --git a/man/man1/rndf.1 b/man/man1/rndf.1
new file mode 100644
index 00000000..522d44e1
--- /dev/null
+++ b/man/man1/rndf.1
@@ -0,0 +1,19 @@
+.TH RNDF 1 "August 2016" "Manual page for rndf"
+.SH NAME
+.B rndf
+\- return a low-quality random choice of a random file in a directory
+.SH SYNOPSIS
+.B rndf
+.br
+.B rndf
+/path/to/dir
+.br
+.SH DESCRIPTION
+.B rndf
+prints the name a random file (excluding dot files) from the given directory,
+defaulting to the current directory. It uses rndi(1), which is not a
+high-quality random number source.
+.SH SEE ALSO
+rndi(1)
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>