# ~/.zshrc optimized for performance


### 🚀 Performance Tweaks
# Avoid compaudit delays unless root
autoload -Uz compinit
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh/cache
if [[ $EUID -ne 0 ]]; then
  compinit -C -d ~/.zsh/cache/zcompdump
else
  compinit -d ~/.zsh/cache/zcompdump
fi

# TMP profiler
# zmodload zsh/zprof

### 📦 Plugin & Framework Setup
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="robbyrussell"
plugins=(nvm git sudo systemadmin)

# Lazy-load nvm
zstyle ':omz:plugins:nvm' lazy yes

source $ZSH/oh-my-zsh.sh


### 🔧 Environment Config
export EDITOR=nano
export VISUAL=nano
export ANDROID_HOME="$HOME/Android/Sdk"
export LIBVIRT_DEFAULT_URI="qemu:///system"

# Set path at the start to ensure all commands can find their binaries
export PATH="/usr/bin:$PATH"
export PATH="$HOME/.local/bin:$PATH"
export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH"
export PATH="$ANDROID_HOME/platform-tools:$PATH"
export PATH="$ANDROID_HOME/cmdline-tools/latest/bin:$PATH"
export PATH="$HOME/.pub-cache/bin:$PATH"
export PATH="/opt/flutter/flutter/bin:$PATH"
export PATH="$HOME/go/bin:$PATH"
export PATH="$HOME/Downloads/go/bin:$PATH"
export PATH="$HOME/Downloads/idea-IU-232.10072.27/bin:$PATH"
export PATH="$HOME/exe/zig-linux-x86_64-0.13.0:$PATH"
export PATH="$HOME/Downloads/javacc-javacc-7.0.13/javacc-javacc-7.0.13/scripts:$PATH"
export PATH="$HOME/.atuin/bin:$PATH"

### ⚙️ Tools Init
eval "$(zoxide init --cmd cd zsh)"
eval "$(oh-my-posh init zsh --config ~/theme.omp.json)"
eval "$(atuin init zsh --disable-up-arrow)"
bindkey '^[[1;5A' atuin-up-search

. "$HOME/.atuin/bin/env"

export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init - zsh)"

# Zellij auto-start
ZELLIJ_AUTO_EXIT=true
eval "$(zellij setup --generate-auto-start zsh)"

### 🐚 Shell Options
setopt NO_SHARE_HISTORY

### 💻 Aliases
alias reload='exec zsh'
alias hcurl='curl --doh-url https://hnsdoh.com/dns-query'
alias ls='eza --icons=auto'
alias ll='eza --long --group --header --icons --classify'
tre() { command tre "$@" && source "/tmp/tre_aliases_$USER" 2>/dev/null; }
alias tree=tre
alias z='zellij'
alias za='zellij attach'
alias open='xdg-open'
alias vim="nvim"
alias vi="nvim"


# ani-cli with preview
alias ani-cli='FZF_DEFAULT_OPTS= ani-cli'

# Personal scripts
for cmd in opacity op blur music copy upload upload_latest_video ts hold message dockerstart dockerstop domains wallpaper cert mount_ssd umount_ssd; do
  alias $cmd="$HOME/scripts/${cmd}.sh"
done

alias venv="source $HOME/scripts/venv.sh"
alias upload_latest_video='$HOME/scripts/upload_latest_video.py'
alias domains='$HOME/scripts/domains.py'

# GitKraken CLI
unalias gk 2>/dev/null

# unzip to folder
unzip() {
  /usr/bin/unzip -d "${1%.*}" "$1"
}

# FZF config
export FZF_DEFAULT_OPTS='--preview "bat --color=always {}"'

# Completion paths
fpath+=(${ZDOTDIR:-~}/.zsh_functions)
FPATH+="$HOME/Git/eza/completions/zsh"
export FPATH
