# The mesh's block (module zsh, novox/hq ADR 0204): the defaults every machine shares, and the code
# other modules contribute in three slots. It is replaced at every push. Everything below it is
# yours, kept as you wrote it, and runs after it, so your lines win.

# History, kept across sessions and shared between open shells. Without these zsh saves none:
# SAVEHIST defaults to 0 (novox/hq to-be 41, found on review 2026-10-04).
HISTFILE="$HOME/.zsh_history"
HISTSIZE=100000
SAVEHIST=100000
setopt EXTENDED_HISTORY SHARE_HISTORY HIST_IGNORE_DUPS HIST_IGNORE_SPACE HIST_REDUCE_BLANKS

# The completion system. Nothing initialised it, so only zsh's basic completion ran. Its cache
# goes under ~/.cache rather than beside ~/.zshrc.
[[ -d "$HOME/.cache/zsh" ]] || mkdir -p "$HOME/.cache/zsh"
autoload -Uz compinit && compinit -d "$HOME/.cache/zsh/zcompdump"
zstyle ':completion:*' menu select

# Terminal title: host, directory, git branch
function set_terminal_title() {
  local git_branch=""
  if git rev-parse --is-inside-work-tree &>/dev/null; then
    git_branch=" ($(git branch --show-current 2>/dev/null))"
  fi
  print -Pn "\e]2;%m: %~${git_branch}\a"
}
precmd_functions+=(set_terminal_title)

# Keybindings
bindkey  "^[[H"   beginning-of-line   # Home
bindkey  "^[OH"   beginning-of-line   # Home
bindkey  "^A"   beginning-of-line     # Ctrl + A
bindkey  "^[[F"   end-of-line         # End
bindkey  "^[OF"   end-of-line         # End
bindkey  "^E"   end-of-line           # Ctrl + E
bindkey  "^[[3~"  delete-char         # Del

# Colour support of ls and friends
if [ -x /usr/bin/dircolors ]; then
  test -r $HOME/.dircolors && eval "$(dircolors -b $HOME/.dircolors)" || eval "$(dircolors -b)"
  alias ls='ls --color=auto'
  alias dir='dir --color=auto'
  alias vdir='vdir --color=auto'
  alias grep='grep --color=auto'
  alias fgrep='fgrep --color=auto'
  alias egrep='egrep --color=auto'
fi
alias ll='ls -alhF'
alias la='ls -Ah'
alias l='ls -CFh'

# A throwaway container, and what takes the space under a directory
alias drun='docker run -it --rm'
disksize() {
  du -h --max-depth=1 "${1:-.}" | sort -h
}
sudo-disksize() {
  sudo du -h --max-depth=1 "${1:-.}" | sort -h
}

# claude-code
# The agent's session (module claude-code, novox/hq ADR 0266): where this machine names an account of the
# agents' own, claude in an interactive zsh is claude-agent, which starts the session as that account. Where
# agents run as the operator's account the file names that account, and nothing is added. claude-agent runs
# the real claude: exec, sudo and its sh see no alias.
if [[ -r /etc/claude-code/agent-account ]]; then
	() {
		local agent=$(</etc/claude-code/agent-account)
		if [[ -n $agent && $agent != $USERNAME ]]; then
			alias claude=claude-agent
		fi
	}
fi
# mesh-cli
# The operator's command (module mesh-cli, novox/hq ADR 0272): nox is mesh-cli, in interactive zsh only.
# A script, sudo and a document meant to work everywhere say mesh-cli.
alias nox=mesh-cli
# powerlevel10k
# The prompt: powerlevel10k v1.20.0, pinned in this module (novox/hq ADR 0205), and its configuration.
[[ ! -f ~/.local/share/powerlevel10k/powerlevel10k.zsh-theme ]] || source ~/.local/share/powerlevel10k/powerlevel10k.zsh-theme
[[ ! -f ~/.config/powerlevel10k/p10k.zsh ]] || source ~/.config/powerlevel10k/p10k.zsh
# zsh-autosuggestions
# Suggestions from history as you type, from the distribution's package.
[[ ! -f /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh ]] || source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
# zsh-syntax-highlighting
# Syntax highlighting of the command line, from the distribution's package. Last, as upstream asks:
# it wraps every widget defined before it.
[[ ! -f /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]] || source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

