# Enable Powerlevel10k instant prompt
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

# Config
HISTFILE=~/.config/zsh/.histfile
HISTSIZE=10000
SAVEHIST=10000
setopt beep extendedglob notify
unsetopt autocd nomatch
bindkey -e

autoload -Uz compinit
compinit

# Exports
export TERM="kitty"

if [ -S "/run/user/$(id -u)/docker.sock" ]; then
  export DOCKER_HOST="unix:///run/user/$(id -u)/docker.sock"
elif [ -S "/var/run/docker.sock" ]; then
  export DOCKER_HOST="unix:///var/run/docker.sock"
fi

# Aliases
alias imgedit=gthumb
alias disk=ncdu
alias dl-yt="bash $HOME/.local/scripts/yt-dlp/download.sh"
alias compress-video="bash $HOME/.local/scripts/ffmpeg/compress-video.sh"
alias convert-gif="bash $HOME/.local/scripts/ffmpeg/convert-gif-to-mp4.sh"

# chezetc fix for root shell
chezetc() {
  if [[ $1 == cd ]]; then
    local dir
    if [[ -z $2 ]]; then
      dir=${HOME}/.local/share/chezetc
    else
      dir=$(command chezetc source-path "$2") || return
    fi
    cd -- "$dir" || return
    return
  fi
  command chezetc "$@"
}

# lazy
lg() {
  lazygit "$@"
}

ld() {
  lazydocker "$@"
}

# docker
dcu() {
	docker compose up -d
}

dcl() {
	docker compose logs -ft
}

dcd() {
	docker compose down
}

# Theme
ZSH_THEME="powerlevel10k/powerlevel10k"

COMPLETION_WAITING_DOTS="true"

plugins=(
  extract
  fzf
  git
	ssh-agent
  zsh-autosuggestions
  zsh-syntax-highlighting
)

# Auto-suggest
ZSH_AUTOSUGGEST_STRATEGY=(history completion)

# Completions
fpath+=${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions/src
autoload -U compinit && compinit

# Load OMZ
source $ZSH/oh-my-zsh.sh

# User configuration

# Set personal aliases, overriding those provided by Oh My Zsh libs,
# plugins, and themes. Aliases can be placed here, though Oh My Zsh
# users are encouraged to define aliases within a top-level file in
# the $ZSH_CUSTOM folder, with .zsh extension. Examples:
# - $ZSH_CUSTOM/aliases.zsh
# - $ZSH_CUSTOM/macos.zsh
# For a full list of active aliases, run `alias`.

# To customize prompt, run `p10k configure` or edit ~/.config/zsh/.p10k.zsh.
[[ ! -f ~/.config/zsh/.p10k.zsh ]] || source ~/.config/zsh/.p10k.zsh

# Add identities
ssh-add ~/.ssh/* 2>/dev/null

# zoxide
eval "$(zoxide init zsh)"
