diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | README.markdown | 1 | ||||
-rw-r--r-- | bin/dam.sh | 25 | ||||
-rw-r--r-- | man/man1/dam.1df | 15 |
5 files changed, 43 insertions, 0 deletions
@@ -16,6 +16,7 @@ bin/clog bin/clrd bin/clwr bin/csmw +bin/dam bin/d2u bin/ddup bin/dmp @@ -89,6 +89,7 @@ BINS = bin/ap \ bin/clrd \ bin/clwr \ bin/csmw \ + bin/dam \ bin/d2u \ bin/ddup \ bin/dmp \ diff --git a/README.markdown b/README.markdown index 06e585ef..1738af22 100644 --- a/README.markdown +++ b/README.markdown @@ -469,6 +469,7 @@ Installed by the `install-bin` target: line. * `csmw(1df)` prints an English list of monospace-quoted words read from the input. +* `dam(1df)` buffers all its input before emitting it as output. * `ddup(1df)` removes duplicate lines from unsorted input. * `dmp(1df)` copies a pass(1) entry selected by `dmenu(1)` to the X CLIPBOARD. diff --git a/bin/dam.sh b/bin/dam.sh new file mode 100644 index 00000000..03424515 --- /dev/null +++ b/bin/dam.sh @@ -0,0 +1,25 @@ +# Store up all input before emitting it unchanged as output +self=dam + +# Create a temporary directory with name in $td, and handle POSIX-ish traps to +# remove it when the script exits. +td= +cleanup() { + [ -n "$td" ] && rm -fr -- "$td" + if [ "$1" != EXIT ] ; then + trap - "$1" + kill "-$1" "$$" + fi +} +for sig in EXIT HUP INT TERM ; do + # shellcheck disable=SC2064 + trap "cleanup $sig" "$sig" +done +td=$(mktd "$self") || exit + +# We'll operate on stdin in the temp directory; write the script's stdin to it +# with cat(1) +cat -- "${@:-}" >"$td"/stdin + +# Only when that write is finished do we finally spit it all back out again +cat -- "$td"/stdin diff --git a/man/man1/dam.1df b/man/man1/dam.1df new file mode 100644 index 00000000..b9821960 --- /dev/null +++ b/man/man1/dam.1df @@ -0,0 +1,15 @@ +.TH DAM 1df "May 2017" "Manual page for dam" +.SH NAME +.B dam +\- read all input before emitting as output +.SH SYNOPSIS +prog1 | +.B +dam +| prog2 +.SH DESCRIPTION +.B dam +stores all its input in a temporary file before emitting it as output, behaving +like a fully-buffered cat(1), and with some of the functionality of sponge(1). +.SH AUTHOR +Tom Ryder <tom@sanctum.geek.nz> |