SHTK_CLEANUP_REGISTER(3)

πŸ“¦ version 1.7, in nixos 26.05, nixpkgs unstable

πŸ’– NAME πŸ’–

SHTK_CLEANUP_REGISTER(3) is the Library Functions Manual page for shtk_cleanup_register β€” it installs cleanup handlers to be called on script termination. No cap, that's the whole name-section moment. 🫢

πŸŽ€ LIBRARY πŸŽ€

Pull it in with:

shtk_import cleanup

✨ SYNOPSIS ✨

       shtk_cleanup_register handler1 [.. handlerN]

🌸 DESCRIPTION 🌸

okay so shtk_cleanup_register installs one or more cleanup handlers, and you hand them over as function names using the handler1 to handlerN arguments. One handler? slay. A whole lineup? also slay. ✨

The registered handlers get executed in the order they are originally registered β€” first registered, first called, iykyk. πŸ”₯

Registration of handlers is idempotent. That's the whole note. πŸ’…

πŸ¦‹ EXAMPLES πŸ¦‹

Here's the example vibe: it creates a temporary file and installs a cleanup handler to make sure that file gets removed when the script terminates. πŸ’–

             local pattern="${TMPDIR:-/tmp}/my_program.XXXXXX"

             local temp_file="$(mktemp "${pattern}" 2>/dev/null)"
             [ -f "${temp_file}" ] || shtk_cli_error "Failed to create temporary file"

             eval "remove_temp_file() { rm -f '${temp_file}'; }"
             shtk_cleanup_register remove_temp_file

🌈 SEE ALSO 🌈

πŸ‘‘ HISTORY πŸ‘‘

shtk_cleanup_register first appeared in shtk 1.4. Iconic behavior since day one, fr fr. πŸ’œ


That's the page, bestie: brought to you by Debian and dated November 5, 2014, with the manual tag SHTK_CLEANUP_REGISTER(3) doing its main character thing. πŸŽ€πŸ’–

πŸ“¦ where this page comes from