# ================================
# zsh configuration
# ================================

# ================================
# Plugin Management (Zinit)
# ================================

# Initialize Zinit
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
if [ ! -d "$ZINIT_HOME" ]; then
   mkdir -p "$(dirname $ZINIT_HOME)"
   git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
fi
source "${ZINIT_HOME}/zinit.zsh"

# Load plugins
# Arch Linux standard plugins (prefer pacman versions when available)
# pacman -S zsh-syntax-highlighting zsh-autosuggestions
if [[ -f /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]]; then
    source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
else
    zinit light zsh-users/zsh-syntax-highlighting
fi

if [[ -f /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh ]]; then
    source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
else
    zinit light zsh-users/zsh-autosuggestions
fi

# Additional useful plugins
zinit light zsh-users/zsh-completions
zinit light Aloxaf/fzf-tab

# Note: Removed dependency on syui---powerline.zsh plugin
# Powerline functionality is now integrated directly above

# Load completions
autoload -U compinit && compinit

# Plugin configurations
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#666666"

# History
HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_IGNORE_SPACE
setopt HIST_FIND_NO_DUPS
setopt HIST_REDUCE_BLANKS
setopt SHARE_HISTORY

# Directory navigation
setopt AUTO_CD
setopt AUTO_PUSHD
setopt PUSHD_IGNORE_DUPS

# Completion
autoload -Uz compinit
compinit
setopt AUTO_MENU
setopt COMPLETE_ALIASES

# Key bindings
bindkey -e
bindkey '^R' history-incremental-search-backward

# ================================
# Airline.zsh Plugin
# ================================

# Load airline.zsh plugin via zinit
zinit load syui/airline.zsh

# Aliases
alias ll='ls -la'
alias la='ls -a'
alias l='ls -CF'
alias grep='grep --color=auto'
alias ..='cd ..'
alias ...='cd ../..'

# Git aliases
alias g='git'
alias gs='git status'
alias ga='git add'
alias gc='git commit'
alias gp='git push'
alias gl='git log --oneline'
alias gd='git diff'

# Tmux aliases
alias t='tmux'
alias ta='tmux attach'
alias tl='tmux list-sessions'

# Functions
mkcd() {
    mkdir -p "$1" && cd "$1"
}

# Load local zshrc if exists
[[ -f ~/.zshrc.local ]] && source ~/.zshrc.local

# Environment variables
export EDITOR=nvim
export VISUAL=nvim
export PAGER=less
export LESS='-R'

# Path additions
export PATH="$PATH:$HOME/.local/bin"
export PATH="$PATH:$HOME/bin"
export PATH="/usr/local/sbin:$PATH"
export PATH="$HOME/.cargo/bin:$PATH"

case $OSTYPE in
	darwin*)
		export PATH="/opt/homebrew/bin:$PATH"
		export PATH="/opt/homebrew/sbin:$PATH"
	;;
	linux*)
	;;
esac

