aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-03 11:43:13 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-03 11:43:13 +1200
commit3e1906b43550efdc4cd18226b03bbd5d11c83433 (patch)
tree70ee9ead23528df6220e820ba0bce57fbaeec57a
parentAdd mktd(1) (diff)
downloaddotfiles-3e1906b43550efdc4cd18226b03bbd5d11c83433.tar.gz
dotfiles-3e1906b43550efdc4cd18226b03bbd5d11c83433.zip
Have rndl(1) use a tempfile
-rwxr-xr-xbin/rndl14
-rw-r--r--man/man1/rndl.15
2 files changed, 14 insertions, 5 deletions
diff --git a/bin/rndl b/bin/rndl
index 416c96be..17e90470 100755
--- a/bin/rndl
+++ b/bin/rndl
@@ -1,8 +1,16 @@
#!/bin/sh
-# Print a random line from argument files
+# Print a random line from input
+td=
+cleanup() {
+ rm -fr -- "$td"
+}
+for sig in EXIT HUP INT TERM ; do
+ trap cleanup "$sig"
+done
if [ "$#" -eq 0 ] ; then
- printf >&2 'rndl: Need at least one filename\n'
- exit 1
+ td=$(mktd rndl) || exit
+ set -- "$td"/stdin
+ cat >"$td"/stdin
fi
lc=$(sed -- '$=;d' "$@") || exit
ri=$(rndi 1 "$lc") || exit
diff --git a/man/man1/rndl.1 b/man/man1/rndl.1
index 33aa6c87..e9f697b3 100644
--- a/man/man1/rndl.1
+++ b/man/man1/rndl.1
@@ -9,10 +9,11 @@ file
.B rndl
file1 file2 file3
.br
+command |
+.B rndl
.SH DESCRIPTION
.B rndl
-prints a random line from the files given as arguments, using rndi(1) to choose
-it.
+prints a random line from its input, using rndi(1) to choose it.
.SH SEE ALSO
rndi(1), rnda(1), rndf(1), rndn(6)
.SH AUTHOR