# Packaged by spice; do not edit.
: "${SPICE_SHELL_HOOK_PYTHON:?spice shell hook: missing SPICE_SHELL_HOOK_PYTHON}"

_spice_shell_hook_self="${BASH_ENV:?spice shell hook: missing BASH_ENV}"
_spice_shell_hook_dir="${_spice_shell_hook_self%/*}"

if [ -z "${SPICE_SHELL_HOOK_REEXEC_STAGE-}" ]; then
  if [ -n "${BASH_EXECUTION_STRING-}" ]; then
    export SPICE_SHELL_HOOK_REEXEC_STAGE=1
    _spice_shell_bin="${BASH:-bash}"
    if ! command -v "$_spice_shell_bin" >/dev/null 2>&1; then
      printf "%s\n" "spice shell hook: cannot resolve bash for agent-run reexec" >&2
      exit 127
    fi
    if shopt -q login_shell; then
      exec "$SPICE_SHELL_HOOK_PYTHON" -m spice agent run -- "$_spice_shell_bin" -lc "$BASH_EXECUTION_STRING"
      printf "%s\n" "spice shell hook: failed to exec agent run" >&2
      exit 127
    fi
    exec "$SPICE_SHELL_HOOK_PYTHON" -m spice agent run -- "$_spice_shell_bin" -c "$BASH_EXECUTION_STRING"
    printf "%s\n" "spice shell hook: failed to exec agent run" >&2
    exit 127
  fi
  case $- in
    *i*) ;;
    *)
      printf "%s\n" "spice shell hook: cannot agent-run reexec noninteractive shell without an execution string" >&2
      exit 127
      ;;
  esac
fi

if [ -n "${SPICE_SHELL_HOOK_ORIGINAL_ZDOTDIR-}" ]; then
  export ZDOTDIR="$SPICE_SHELL_HOOK_ORIGINAL_ZDOTDIR"
else
  unset ZDOTDIR
fi
if [ -n "${SPICE_SHELL_HOOK_ORIGINAL_BASH_ENV-}" ]; then
  export BASH_ENV="$SPICE_SHELL_HOOK_ORIGINAL_BASH_ENV"
else
  unset BASH_ENV
fi

_spice_shell_real_source="${SPICE_SHELL_HOOK_ORIGINAL_BASH_ENV-}"
if [ -n "$_spice_shell_real_source" ] && [ -r "$_spice_shell_real_source" ] && [ "$_spice_shell_real_source" != "$_spice_shell_hook_self" ]; then
  . "$_spice_shell_real_source"
fi

export ZDOTDIR="$_spice_shell_hook_dir"
export BASH_ENV="${_spice_shell_hook_dir}/bash_env"
eval "${SPICE_SHELL_HOOK_WRAPPERS-}"

unset _spice_shell_bin
unset _spice_shell_hook_dir
unset _spice_shell_hook_self
unset _spice_shell_real_source
