# runex shell integration for bash
# No-op when sourced by a non-interactive shell (`bash -c`, scripts, CI).
case $- in
  *i*) ;;
  *) return 0 ;;
esac
# === Cygwin/MSYS (Git Bash) bake-mode dispatcher (issue #7) ================
# In Git Bash spawning a Win32 .exe from inside the trigger handler causes
# the next SIGINT to be lost. To avoid that, the cygwin path looks the
# abbreviation up in a static table baked into this cache file. The block
# below is generated by app::bash_static_dispatcher and is empty when
# runex export bash is invoked without a config (legacy escape hatch).
{BASH_CYG_DISPATCHER}
# === Linux / WSL / generic bash exec dispatcher (legacy path) ==============
__runex_exec_expand() {
    local out
    if out=$({BASH_BIN} hook --shell bash --line "$READLINE_LINE" --cursor "$READLINE_POINT" 2>/dev/null) && [ -n "$out" ]; then
        eval "$out"
    else
        READLINE_LINE="${READLINE_LINE:0:READLINE_POINT} ${READLINE_LINE:READLINE_POINT}"
        READLINE_POINT=$((READLINE_POINT + 1))
    fi
}
# === Public entry point ====================================================
# The trigger handler invokes __runex_expand. Selection is done once at
# source time because OSTYPE is immutable per session: under msys/cygwin
# (Git Bash) we route to the bake path if it was emitted (config-driven),
# otherwise we keep the exec path. The bake path is empty when
# runex export bash was called without a config (legacy escape hatch),
# so we fall back to exec by checking whether the bake function exists.
case "${OSTYPE-}" in
    msys*|cygwin*)
        if declare -F __runex_cyg_expand >/dev/null 2>&1; then
            __runex_expand() { __runex_cyg_expand; }
        else
            __runex_expand() { __runex_exec_expand; }
        fi
        ;;
    *)
        __runex_expand() { __runex_exec_expand; }
        ;;
esac
__runex_self_insert() {
    READLINE_LINE="${READLINE_LINE:0:READLINE_POINT} ${READLINE_LINE:READLINE_POINT}"
    READLINE_POINT=$((READLINE_POINT + 1))
}
{BASH_BIND_LINES}
{BASH_SELF_INSERT_LINES}
