# ============================================================================
# Fast compinit - cache completions, regenerate once daily
# ============================================================================
autoload -Uz compinit
if [[ -n ${ZDOTDIR:-$HOME}/.zcompdump(#qN.mh+24) ]]; then
  compinit
else
  compinit -C
fi

# ~/.zshrc - Zsh configuration for interactive shells
# Customizations are in ~/.oh-my-zsh/custom/*.zsh (auto-loaded)

# ============================================================================
# Oh-My-Zsh Configuration (BEFORE sourcing oh-my-zsh.sh)
# ============================================================================

# Path to oh-my-zsh installation
export ZSH="$HOME/.oh-my-zsh"

# Theme - see https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="bira-time"

# Case-insensitive completion (a-z matches A-Z)
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'

# Hyphen-insensitive completion (_ and - are interchangeable)
HYPHEN_INSENSITIVE="true"

# Disable automatic updates (update manually with: omz update)
zstyle ':omz:update' mode disabled

# Show red dots while waiting for completion
COMPLETION_WAITING_DOTS="true"

# Don't mark untracked files as dirty (faster for large repos)
DISABLE_UNTRACKED_FILES_DIRTY="true"

# History timestamp format
HIST_STAMPS="dd.mm.yyyy"

# History settings
HISTSIZE=10000
SAVEHIST=10000

# Plugins - loaded from $ZSH/plugins/ and $ZSH_CUSTOM/plugins/
# Keep this list minimal for fast startup
plugins=(
    git
    encode64
    gitignore
    z
)

# Skip compinit in oh-my-zsh (we handle it above)
export ZSH_DISABLE_COMPFIX=true
skip_global_compinit=1

# ============================================================================
# Load Oh-My-Zsh
# ============================================================================
source $ZSH/oh-my-zsh.sh

# ============================================================================
# Post-OMZ Settings
# ============================================================================

# Enable extended glob patterns
setopt extendedglob

# Disable command_not_found handler (can be slow)
unset command_not_found_handle

# Color man pages
export LESS_TERMCAP_mb=$'\e[1;32m'
export LESS_TERMCAP_md=$'\e[1;32m'
export LESS_TERMCAP_me=$'\e[0m'
export LESS_TERMCAP_se=$'\e[0m'
export LESS_TERMCAP_so=$'\e[01;33m'
export LESS_TERMCAP_ue=$'\e[0m'
export LESS_TERMCAP_us=$'\e[1;4;31m'

# ============================================================================
# Files in ~/.oh-my-zsh/custom/ are auto-loaded:
#   - aliases.zsh     : All aliases
#   - functions.zsh   : All functions
#   - path.zsh        : PATH modifications
#   - prompt.zsh      : Custom prompt
#   - keybindings.zsh : Key bindings
#   - secrets.zsh     : API tokens (gitignored)
#   - tools/*.zsh     : Tool-specific configs (pyenv, nvm, kubectl)
# ============================================================================

czpush() {
  local msg="${1:-Update dotfiles}"
  cd "$(chezmoi source-path)" && git add -A && git commit -m "$msg" && git push
  cd - > /dev/null
}
