diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-10 23:49:20 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-10 23:51:10 +1300 |
commit | 0053948a95d09f7e20b40e5ab643dfa580f45375 (patch) | |
tree | 002d988bfe6c42dbc29e27b922fc92f56d4b5a9d /bin | |
parent | Merge branch 'feature/vim-sh-syn' into develop (diff) | |
download | dotfiles-0053948a95d09f7e20b40e5ab643dfa580f45375.tar.gz dotfiles-0053948a95d09f7e20b40e5ab643dfa580f45375.zip |
Fix oii(1df) so it works as a pipe
I realised I could make this work by recording a single byte in the
temporary file with dd(1) and then emitting that and then the rest of
the input with cat(1) if the file ended up with a byte in it.
This lets me remove the CAVEATS section from the manual, as it no longer
applies.
Diffstat (limited to 'bin')
-rw-r--r-- | bin/oii.mi5 | 13 |
1 files changed, 7 insertions, 6 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" - | "$@" |