# Start mesuring bottlenecks
if [[ "$ZPROF" = true ]]; then
    zmodload zsh/zprof
fi

## Stuff I don't know what they're for
# autoload -Uz compinit
# compinit

#--------------------------------------------------------------------#
#                             ZSH Config                             #
#--------------------------------------------------------------------#

# this should before placed before `"$ZSH/oh-my-zsh.sh"`
# Color scheme for syntax highlighting
source ~/.config/zsh/themes/catppuccin_macchiato-zsh-syntax-highlighting.zsh

fpath+=${ZSH_CUSTOM:-${ZSH:-$XDG_DATA_HOME/oh-my-zsh}/custom}/plugins/zsh-completions/src
fpath+=${XDG_CONFIG_HOME:-$DOTS/config}/zsh/completions

# set VIM keybindings
bindkey -v

# Path to your oh-my-zsh installation.
export ZSH="$HOME/.local/share/oh-my-zsh"

ZSH_THEME="gozilla"

# Case-sensitive completion must be off. _ and - will be interchangeable.
HYPHEN_INSENSITIVE="true"

DISABLE_AUTO_TITLE="true"

# Uncomment the following line to display red dots whilst waiting for completion.
COMPLETION_WAITING_DOTS="true"

# Read Git repos much faster.
DISABLE_UNTRACKED_FILES_DIRTY="true"

# search if exist an alias for the executed command
ZSH_ALIAS_FINDER_AUTOMATIC=true

#--------------------------------------------------------------------#
#                           Plugin Config                            #
#--------------------------------------------------------------------#

# VI_MODE_RESET_PROMPT_ON_MODE_CHANGE=true
# VI_MODE_SET_CURSOR=true

ZSHZ_TILDE=1

plugins=(
    alias-finder
    # archlinux
    bgnotify
    colored-man-pages
    docker
    docker-compose
    fd
    fzf
    git
    safe-paste # don't run code when pasting
    systemd
    z
    zsh-autocomplete
    zsh-autopair
    zsh-autosuggestions
    zsh-completions
    zsh-syntax-highlighting
    zsh-interactive-cd
)

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

export HISTCONTROL=ignoreboth:erasedups

# autocomplete: https://github.com/marlonrichert/zsh-autocomplete/blob/main/.zshrc
zstyle ':autocomplete:*' fzf-completion yes
zstyle ':autocomplete:*' min-input 1
zstyle ':autocomplete:*' widget-style menu-select # Tab select instead of autocomplete

source $ZSH/oh-my-zsh.sh

#--------------------------------------------------------------------#
#                            Start Stuff                             #
#--------------------------------------------------------------------#

# File directory that are needed to source
files=(
    # zsh
    $DOTS/config/zsh/**/*.zsh
    # fzf scripts that need to be sourced
    $DOTS/scripts/fzf-flatpak
    # fzf config file
    $DOOTS/config/fzf/fzfrc
)

for file in $files; do
    if [[ -f $file ]]; then
        emulate -L zsh
        source $file
    fi
done


if [[ "$ZPROF" = true ]]; then
    zprof
fi

eval "$(starship init zsh)"
eval "$(rtx activate zsh)"
