I implemented defer as a bash loadable builtin.It is a wrapper over the trap builtin that chains handlers on signals instead of replacing them (LIFO order):
https://github.com/leagris/bash-loadable-deferPosting here in case it is of interest or worth considering as a core builtin feature.
-- Léa Gris
