aboutsummaryrefslogtreecommitdiff
path: root/bin/rndl
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 /bin/rndl
parentAdd mktd(1) (diff)
downloaddotfiles-3e1906b43550efdc4cd18226b03bbd5d11c83433.tar.gz
dotfiles-3e1906b43550efdc4cd18226b03bbd5d11c83433.zip
Have rndl(1) use a tempfile
Diffstat (limited to 'bin/rndl')
-rwxr-xr-xbin/rndl14
1 files changed, 11 insertions, 3 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