aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-06-02 22:07:52 +1200
committerTom Ryder <tom@sanctum.geek.nz>2017-06-02 22:07:52 +1200
commitbc1d5fb28841f6050605e93886685b3a02e7787a (patch)
treef0f02d8d4884b0864334ad774c98da87c0301379 /include
parentCorrect some terms in man mi5(1df) (diff)
downloaddotfiles-bc1d5fb28841f6050605e93886685b3a02e7787a.tar.gz
dotfiles-bc1d5fb28841f6050605e93886685b3a02e7787a.zip
Use mi5 to make templated shell scripts
Diffstat (limited to 'include')
-rw-r--r--include/mktd.mi515
1 files changed, 15 insertions, 0 deletions
diff --git a/include/mktd.mi5 b/include/mktd.mi5
new file mode 100644
index 00000000..388eb9be
--- /dev/null
+++ b/include/mktd.mi5
@@ -0,0 +1,15 @@
+# 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