# History
HISTFILE="$HOME/.zsh_history"
HISTSIZE=10000
SAVEHIST=10000
setopt share_history

# Aliases
alias gp='git push'
alias gcm='git commit -am'
alias gsw='git switch'
alias gst='git status'
alias ga='git add .'
alias gtree="git log --graph --all --pretty=format:'%C(yellow)%h%Creset%C(cyan)%d%Creset %s %C(dim)(%cr) <%an>%Creset'"

# Environment
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
export GOPATH="${GOPATH:-$HOME/go}"
export PATH="$HOME/.scripts:$HOME/.local/bin:$HOME/.cargo/bin:$HOME/.bun/bin:$HOME/bin/zig:$HOME/bin/zls:$GOPATH/bin:$PATH"

# SSH agent
start-ssh-agent() {
    local agent_env="$HOME/.ssh/agent.env"
    if [[ -f "$agent_env" ]]; then
        source "$agent_env" >/dev/null
    fi
    if ! ssh-add -l &>/dev/null; then
        eval "$(ssh-agent -s)" >/dev/null
        ssh-agent -s >"$agent_env"
        chmod 600 "$agent_env"
        ssh-add ~/.ssh/id_ed25519 2>/dev/null || ssh-add ~/.ssh/id_rsa 2>/dev/null
    fi
}

# Clipboard via OSC 52 (works through tmux, including remote sessions)
clip() {
    local input
    if [ -t 0 ]; then
        input="$*"
    else
        input=$(cat)
    fi
    printf "\033]52;c;%s\007" "$(echo -n "$input" | base64)" > "$(tmux display-message -p '#{client_tty}')"
}

# Plugins
source /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh
source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

eval "$(fzf --zsh)"
eval "$(starship init zsh)"

. "$HOME/.atuin/bin/env"
eval "$(atuin init zsh)"
