tempfile.nim
tempfile.nim copied to clipboard
option for guaranteed auto cleanup using file descriptor trick
this answer uses a nice trick to guarantee auto cleanup:
tmpfile=$(mktemp /tmp/abc-script.XXXXXX)
exec 3>"$tmpfile"
rm "$tmpfile"
: ...
echo foo >&3
the cleanup would happen even if a crash happens (or, say, a quit):
When it gets closed (which the kernel does automatically when the process exits) the filesystem deletes the file
the same trick could be used (as option!) in tempfile API
thank you!