aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-05-24 15:57:34 +1200
committerTom Ryder <tom@sanctum.geek.nz>2017-05-24 15:57:34 +1200
commit1c7cf90afae80918b82d823af59484f84391814f (patch)
tree96aef76b22715d7b9a548684479470923cd464db /bin
parentCorrect title of pvi(1df) man page (diff)
downloaddotfiles-1c7cf90afae80918b82d823af59484f84391814f.tar.gz
dotfiles-1c7cf90afae80918b82d823af59484f84391814f.zip
Add dam(1df)
Diffstat (limited to 'bin')
-rw-r--r--bin/dam.sh25
1 files changed, 25 insertions, 0 deletions
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