{{- if (eq .host.headless true) }}
#!/usr/bin/env bash
# @file ZSH Pre-Initialization
# @brief Ensures ZSH is pre-initialized by invoking ZSH and allowing it to perform "first-run" tasks
# @description
#     This script ensures that the first time you open a ZSH terminal session everything is loaded as fast as possible.
#     It does this by invoking ZSH in the background during the provisioning process so that "first-run" tasks such
#     as cache-building are handled ahead of time.

# .zshrc hash: {{ include (joinPath .chezmoi.homeDir ".zshrc") | sha256sum }}

{{ includeTemplate "universal/profile" }}
{{ includeTemplate "universal/logg" }}

### Initialize ZSH so plugin bootstrap process is done ahead of time
if command -v zsh > /dev/null; then
  logg info 'Bootstrapping ZSH by running exec zsh'
  exec zsh &
  logg info 'Waiting for exec zsh to finish'
  wait
fi
{{ end -}}
