# CNW zshrc — chezmoi-managed (dotfiles repo, Redmine #612)
# Home base: ultix-streaming (VM 5111). Minimal interactive footprint
# anywhere else; heavy lifting happens in containers.
#
# Layers: oh-my-zsh + powerlevel10k, fzf, vi mode, ~/.config/zsh/* snippets.

#####################################################################
# oh-my-zsh
#####################################################################

export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="powerlevel10k/powerlevel10k"

# externals in .chezmoiexternal.toml own updates
zstyle ':omz:update' mode disabled

ENABLE_CORRECTION="true"
DISABLE_UNTRACKED_FILES_DIRTY="true"
HIST_STAMPS="yyyy-mm-dd"

plugins=(
  git
  sudo
  z
  extract
  copypath
  colored-man-pages
  command-not-found
  zsh-completions
  zsh-autosuggestions
  zsh-syntax-highlighting
)

source $ZSH/oh-my-zsh.sh

# powerlevel10k (run `p10k configure` any time for the fancy wizard)
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh

#####################################################################
# Creature comforts
#####################################################################

# vi mode, 24x7 — this isn't a holiday inn
bindkey -v
export KEYTIMEOUT=1
set -o vi

export EDITOR='vim'
export VISUAL='vim'
export PAGER='less'
export LESS='-R'

# Debian's fd-find ships fdfind; make it fd
command -v fdfind >/dev/null 2>&1 && alias fd='fdfind'
# Debian's bat ships batcat
command -v batcat >/dev/null 2>&1 && alias bat='batcat'

#####################################################################
# History
#####################################################################

HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=50000
setopt hist_expire_dups_first
setopt hist_ignore_dups
setopt hist_verify
setopt appendhistory
setopt incappendhistory
HISTDUP=erase
alias history="history 0"

# DO NOT share history across terminals
setopt no_share_history
unsetopt sharehistory

TIMEFMT=$'\nreal\t%E\nuser\t%U\nsys\t%S\ncpu\t%P'

#####################################################################
# fzf (Debian package paths)
#####################################################################

if [[ -r /usr/share/doc/fzf/examples/key-bindings.zsh ]]; then
  source /usr/share/doc/fzf/examples/key-bindings.zsh
fi
if [[ -r /usr/share/doc/fzf/examples/completion.zsh ]]; then
  source /usr/share/doc/fzf/examples/completion.zsh
fi
export FZF_DEFAULT_COMMAND='fdfind --type f --hidden --follow --exclude .git 2>/dev/null || rg --files --hidden --glob "!.git" 2>/dev/null'
command -v fdfind >/dev/null 2>&1 && _fzf_compgen_path() { fdfind --hidden --follow --exclude .git . "$1" 2>/dev/null; }

#####################################################################
# SSH agent — bitwarden agent socket if present (path per-host)
#####################################################################

if [[ -S "$HOME/.bitwarden-ssh-agent.sock" ]]; then
  export SSH_AUTH_SOCK="$HOME/.bitwarden-ssh-agent.sock"
fi

#####################################################################
# Paths and loaders (conditional — hosts without these skip)
#####################################################################

[[ -r "$HOME/.cargo/env" ]] && . "$HOME/.cargo/env"

if command -v mise &> /dev/null; then
  eval "$(mise activate zsh)"
fi

#####################################################################
# Personal snippets (also chezmoi-managed)
#####################################################################

[[ -r "$HOME/.config/zsh/variables.sh" ]] && source "$HOME/.config/zsh/variables.sh"
[[ -r "$HOME/.config/zsh/aliases.sh" ]] && source "$HOME/.config/zsh/aliases.sh"
