SHTK_CONFIG_RUN_HOOK(3)

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

πŸ’… shtk_config_run_hook πŸ’…

okay bestie, welcome to the Library Functions Manual page for shtk_config_run_hook β€” yes, that's the manual name up top, and yes, we're about to make hooks make sense πŸ’–


✨ NAME ✨

shtk_config_run_hook β€” Executes a hook defined in a configuration file. Slay.

πŸŽ€ LIBRARY πŸŽ€

Import it with shtk_import config and you're in, bestie πŸ’…

πŸ¦‹ SYNOPSIS πŸ¦‹

Here's the shape of it:

shtk_config_run_hook hook [arg1 .. argN]

🌸 DESCRIPTION 🌸

The shtk_config_run_hook function executes the function hook, defined by the configuration file, in the same context as the file. Any arguments arg1 to argN are passed literally to the hook. Hooks should not be executed directly, because otherwise they would need to use the shtk_config_get(3) family of functions to read the variables defined in the file, which could be quite strange. Like, why would you do that to yourself? πŸ™ˆ

Keep in mind that the hook will only be able to access the configuration variables previously registered with shtk_config_init(3). Any other variables will be hidden and not available to the hook. That's the vibe check: only registered vars get through.

Don't call hooks directly, bestie β€” use this function so the hook runs in the same context as the file. It's giving "don't skip the group chat and then ask what happened" energy πŸ’€

πŸ”₯ EXAMPLES πŸ”₯

Consider the following configuration file:

SRCDIR=/usr/src

show_srcdir_hook() {
    # Note that we can access SRCDIR directly, as would be normal in a
    # configuration file.  No need to use shtk_config_get.
    echo "SRCDIR is ${SRCDIR}"
}

Then, we could process the file and execute the defined hook like this:

shtk_config_init SRCDIR
shtk_config_load ".../path/to/the/file/above.conf"

# This will print nothing because SRCDIR is not available here.
echo "SRCDIR is ${SRCDIR}"

# But this will display the right SRCDIR value.
shtk_config_run_hook show_srcdir_hook

This is lowkey iconic: the plain echo outside the hook prints nothing because SRCDIR is not available there, but shtk_config_run_hook show_srcdir_hook gets the right value for SRCDIR. ✨

😭 ERRORS 😭

Errors during the execution of the hook result in the termination of the script. So if the hook throws a fit, the script is done β€” no cap, it terminates.

πŸ‘‘ SEE ALSO πŸ‘‘

see also besties:

⭐ HISTORY ⭐

shtk_config_run_hook first appeared in shtk 1.1. Periodt.


And that's the whole page, bestie β€” brought to you by Debian, dated November 6, 2014, filed under SHTK_CONFIG_RUN_HOOK(3) πŸ’–βœ¨

πŸ“¦ where this page comes from