aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-11-10 23:51:23 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-11-10 23:51:23 +1300
commitd50e7f4a648ff8992015f4bc8bc3ea7493cd536a (patch)
tree002d988bfe6c42dbc29e27b922fc92f56d4b5a9d
parentb7139c718f09f011f55db8eebbcd329b621386a8 (diff)
parent0053948a95d09f7e20b40e5ab643dfa580f45375 (diff)
downloaddotfiles-d50e7f4a648ff8992015f4bc8bc3ea7493cd536a.tar.gz
dotfiles-d50e7f4a648ff8992015f4bc8bc3ea7493cd536a.zip
Merge branch 'feature/oii-fix' into develop
* feature/oii-fix: Fix oii(1df) so it works as a pipe
-rw-r--r--bin/oii.mi513
-rw-r--r--man/man1/oii.1df6
2 files changed, 8 insertions, 11 deletions
diff --git a/bin/oii.mi5 b/bin/oii.mi5
index 51f37fb4..914d45f9 100644
--- a/bin/oii.mi5
+++ b/bin/oii.mi5
@@ -11,9 +11,10 @@ fi
include(`include/mktd.m4')
%>
-# There is probably a way better way to do this than writing the whole file to
-# disk and then reading it off again, but until I think of something better,
-# this works and is byte-safe.
-cat - > "$td"/in
-[ -s "$td"/in ] || exit
-"$@" < "$td"/in
+# Read up to one byte and save it into temp file; discard stderr (stats)
+tf=$td/input
+dd bs=1 count=1 of="$tf" 2>/dev/null
+
+# If there's now a byte in the file, spit it and the rest of the input into the
+# requested command
+[ -s "$tf" ] && cat -- "$tf" - | "$@"
diff --git a/man/man1/oii.1df b/man/man1/oii.1df
index f5bb2678..6d1cf601 100644
--- a/man/man1/oii.1df
+++ b/man/man1/oii.1df
@@ -1,4 +1,4 @@
-.TH OII 1df "June 2017" "Manual page for oii"
+.TH OII 1df "November 2017" "Manual page for oii"
.SH NAME
.B oii
\- run a command on input only if there's at least one byte of input
@@ -13,9 +13,5 @@ CMD [ARGS ...]
Run the given program passing in stdin but only if at least one byte of input
is actually received, rather like the -E switch to mail(1) behaves on
bsd-mailx. If no input is received, exit silently with an error status.
-.SH CAVEATS
-It's slow, and doesn't work as a pipe. The entire input is written to disk and
-then tested for filesize before being re-emitted. There's almost certainly a
-more efficient way to do this while still remaining byte-safe.
.SH AUTHOR
Tom Ryder <tom@sanctum.geek.nz>