export TERM=xterm-256color

export XDG_DOWNLOAD_DIR="$HOME/downloads"
export XDG_PROJECTS_DIR="$HOME/programming"
export XDG_DESKTOP_DIR="$HOME"
export XDG_DOCUMENTS_DIR="$HOME/media"
export XDG_MUSIC_DIR="$HOME/media"
export XDG_PICTURES_DIR="$HOME/media"
export XDG_PUBLICSHARE_DIR="$HOME/media"
export XDG_TEMPLATES_DIR="$HOME/media"
export XDG_VIDEOS_DIR="$HOME/media"

export EDITOR=nvim
export SUDO_EDITOR=nvim

export GOPATH="$HOME/.local/go"

export PATH="$HOME/.local/bin:$HOME/.local/go/bin:$HOME/opt/bin:$HOME/.cargo/bin:$PATH"
export LD_LIBRARY_PATH="$HOME/opt/lib:${LD_LIBRARY_PATH:-}"

ZAP_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/zap"
[ -f "$ZAP_DIR/zap.zsh" ] && source "$ZAP_DIR/zap.zsh"

[ -f "$HOME/.zprofile" ] && source "$HOME/.zprofile"

if [ -x /home/linuxbrew/.linuxbrew/bin/brew ]; then
  eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi

HISTFILE="${ZDOTDIR:-$HOME}/.zsh_history"
HISTSIZE=50000
SAVEHIST=50000

setopt APPEND_HISTORY
setopt INC_APPEND_HISTORY
setopt SHARE_HISTORY

setopt EXTENDED_HISTORY
setopt BANG_HIST
setopt HIST_EXPIRE_DUPS_FIRST
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_FIND_NO_DUPS
setopt HIST_IGNORE_SPACE
setopt HIST_SAVE_NO_DUPS
setopt HIST_REDUCE_BLANKS
setopt HIST_VERIFY

setopt AUTO_CD
setopt AUTO_PARAM_SLASH
setopt GLOB_DOTS
setopt EXTENDED_GLOB
setopt INTERACTIVE_COMMENTS
setopt MENU_COMPLETE
setopt NOMATCH
unsetopt BEEP

autoload -Uz compinit colors bashcompinit
zmodload zsh/complist

zstyle ':completion:*' menu yes select
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=*'
_comp_options+=(globdots)
zle_highlight=('paste:none')

if [[ -f "${ZDOTDIR:-$HOME}/.zcompdump" ]]; then
  compinit -C
else
  compinit
fi

bashcompinit

autoload -Uz colors && colors
PS1="%B%{$fg[red]%}[%{$fg[yellow]%}%n%{$fg[green]%}@%{$fg[blue]%}%M %{$fg[magenta]%}%~%{$fg[red]%}]%{$reset_color%}$%b "

bindkey -e
bindkey -s '^x' '^usource $ZSHRC\n'
bindkey -M menuselect '?' history-incremental-search-forward
bindkey -M menuselect '/' history-incremental-search-backward
bindkey '^H' backward-kill-word

autoload -U up-line-or-beginning-search
autoload -U down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search

alias cat='bat'
alias gg='lazygit'
alias v='nvim'
alias cp='cp -v'

take() {
  mkdir -p -- "$1" && cd -- "$1"
}

if (( $+commands[eza] )); then
  alias ls='eza --group-directories-first --icons=auto'
  if eza --version | grep -q '+git'; then
    alias ll='ls -lh --git'
  else
    alias ll='ls -lh'
  fi
  alias la='ll -a'
  alias tree='ll --tree --level=2'
else
  alias ls='ls --group-directories-first'
  alias ll='ls -lh'
  alias la='ll -a'
fi

if ! command -v zap >/dev/null 2>&1; then
  printf 'Installing zap (release-v1)...\n'
  zsh <(curl -s https://raw.githubusercontent.com/zap-zsh/zap/master/install.zsh) --keep --branch release-v1
  if [ -f "${ZDOTDIR:-$HOME}/.zshrc" ]; then
    source "${ZDOTDIR:-$HOME}/.zshrc"
  fi
fi

autoload -Uz plug
plug "zsh-users/zsh-autosuggestions"
plug "zsh-users/zsh-syntax-highlighting"
plug "Aloxaf/fzf-tab"

: "${XDG_DATA_HOME:=$HOME/.local/share}"
: "${XDG_CONFIG_HOME:=$HOME/.config}"
