# forgeOS zsh configuration. It is yours: edit freely.
# Having this file means zsh never starts its first-run setup wizard.

# --- PATH: per-user programs such as Claude Code ----------------------------
typeset -U path
path=("$HOME/.local/bin" $path)

# --- History ----------------------------------------------------------------
HISTFILE=~/.zsh_history
HISTSIZE=50000
SAVEHIST=50000
setopt EXTENDED_HISTORY SHARE_HISTORY HIST_IGNORE_DUPS HIST_IGNORE_SPACE HIST_REDUCE_BLANKS
setopt AUTO_CD INTERACTIVE_COMMENTS NO_BEEP

# --- Tab completion ---------------------------------------------------------
# Tab lists a command's subcommands and options with their descriptions;
# press Tab again (or use the arrow keys) to move through the menu.
autoload -Uz compinit && compinit
zmodload zsh/complist
zstyle ':completion:*' menu select
zstyle ':completion:*' verbose yes
zstyle ':completion:*' group-name ''
zstyle ':completion:*:descriptions' format '%F{208}-- %d --%f'
zstyle ':completion:*:messages' format '%F{yellow}-- %d --%f'
zstyle ':completion:*:warnings' format '%F{red}-- no matches --%f'
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}' 'r:|[._-]=* r:|=*'
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path "${XDG_CACHE_HOME:-$HOME/.cache}/zsh/completion"
# Shift+Tab moves backwards in the completion menu.
bindkey -M menuselect '^[[Z' reverse-menu-complete

# --- Keys: emacs-style editing; Up/Down search history by what you typed -----
bindkey -e
autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
for key in '^[[A' '^[OA'; do bindkey "$key" up-line-or-beginning-search; done
for key in '^[[B' '^[OB'; do bindkey "$key" down-line-or-beginning-search; done
for key in '^[[H' '^[OH' '^[[1~'; do bindkey "$key" beginning-of-line; done
for key in '^[[F' '^[OF' '^[[4~'; do bindkey "$key" end-of-line; done
bindkey '^[[3~' delete-char
bindkey '^[[1;5C' forward-word
bindkey '^[[1;5D' backward-word
bindkey '^H' backward-kill-word

# --- Prompt: user@host, directory, git branch, red % after a failed command --
autoload -Uz vcs_info
precmd() { vcs_info }
zstyle ':vcs_info:git:*' formats ' %F{yellow}(%b)%f'
setopt PROMPT_SUBST
PROMPT='%F{208}%n@%m%f %F{blue}%~%f${vcs_info_msg_0_} %(?.%F{green}.%F{red})%#%f '

# --- Aliases ----------------------------------------------------------------
alias ls='ls --color=auto'
alias ll='ls -lh'
alias la='ls -lAh'
alias grep='grep --color=auto'

# --- Plugins (Arch packages): suggestions from history, colored commands ----
# Right arrow or End accepts the grey suggestion.
[[ -r /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh ]] \
	&& source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
# Must stay last.
[[ -r /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]] \
	&& source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
