#!/bin/bash ffoo import exit ffoo import inigrep ffoo import pretty saturnin_help() { { echo "built-in commands:" echo " conf" echo " help" echo "" echo "installed commands:" saturnin_lssc \ | sed -e 's/^/ /' } | mkhelp -E -f - return "$FFOO_EXIT_OK" } saturnin_lssc() { find "$SATURNIN_LIBEXEC" \ -mindepth 1 \ -maxdepth 1 \ -executable \ | sed -e 's/.*saturnin-//' \ | sort } saturnin_runhook() { # # Run custom hook # local hname="$1" local hook_code test -n "$SATURNIN_SUBCOMMAND" || { warn "unknown subcommand, ignoring hook: $hname" return 0 } hook_code="$(inigrep -j -p "hook.$SATURNIN_SUBCOMMAND.$hname")" debug -v SATURNIN_SUBCOMMAND hook_code hname bash -n <<<"$hook_code" || { warn "syntax errors, ignoring hook: $hname" return 0 } eval "$hook_code" } saturnin_runsc() { local lexpath="$SATURNIN_LIBEXEC/saturnin-$SATURNIN_SUBCOMMAND" debug -v lexpath debug "\$*='$*'" test -x "$lexpath" || { warn "invalid sub-command: $SATURNIN_SUBCOMMAND" saturnin_help return "$FFOO_EXIT_USAGE" } "$lexpath" "$@" } saturnin_wraphook() { # # Wrap command "$@" in hooks # # Run pre hook, then "$@", then post hook. Always exit # with status of "$@", even if hooks fail. Ignore # post-hook if "$@" failed. # local es=0 saturnin_runhook pre "$@" || return $? es=$? saturnin_runhook post return $es }