# set up environment
export PURE_GIT_PULL=0
export GPG_TTY=$(tty)
export HISTSIZE=100000
export HISTFILE="$HOME/.zsh_history"
export SAVEHIST=$HISTSIZE

# set zsh options and features
setopt autocd
autoload -Uz compinit && compinit
setopt extended_history
setopt inc_append_history
setopt share_history
setopt rmstarsilent

# load zsh plugins
[ -f "$HOME/.local/share/zap/zap.zsh" ] && source "$HOME/.local/share/zap/zap.zsh"

function zvm_after_init() {
  plug "zap-zsh/fzf"
  typeset -A key
  key[Home]=${terminfo[khome]}
  key[End]=${terminfo[kend]}
  key[Delete]=${terminfo[kdch1]}
  zvm_bindkey viins "${key[Home]}"  beginning-of-line
  zvm_bindkey vicmd "${key[Home]}"  beginning-of-line
  zvm_bindkey viins "${key[End]}"  end-of-line
  zvm_bindkey vicmd "${key[End]}"  end-of-line
  zvm_bindkey viins "${key[Delete]}" delete-char
  zvm_bindkey vicmd "${key[Delete]}" delete-char
}

plug "mafredri/zsh-async"
plug "sindresorhus/pure"
plug "zsh-users/zsh-autosuggestions"
plug "zsh-users/zsh-syntax-highlighting"
plug "zpm-zsh/ls"
ZAP_GIT_PREFIX="https://code.sitosis.com/" plug "rudism/zsh-bat"
plug "lukechilds/zsh-nvm"
plug "jeffreytse/zsh-vi-mode"

# source external stuff
eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)
source ~/skynet/zsh/catppuccin_mocha-zsh-syntax-highlighting.zsh
source ~/skynet/zsh/zsh-grc

# env and path
export DOTNET_ROOT=$HOME/dotnet
export MOZ_ENABLE_WAYLAND=1
export QT_QPA_PLATFORMTHEME=qt6ct
export LD_LIBRARY_PATH=$HOME/.local/lib:$LD_LIBRARY_PATH
export PATH=$HOME/.local/bin:$HOME/dotnet:$HOME/.dotnet/tools:$HOME/go/bin:$HOME/.cargo/bin:$HOME/node/node_modules/.bin:$PATH

# keybindings
bindkey "^[[1~" beginning-of-line
bindkey "^[[4~" end-of-line
bindkey "^[[3~" delete-char

# set up directory hashes
if [ -f ~/.zalias ]; then
  source ~/.zalias
fi

if [ -d "$HOME/.config/plasma-workspace/env" ]; then
  for sh in $HOME/.config/plasma-workspace/env/*.sh; do
    source "$sh"
  done
fi

# load tmux if it exists and we're not in it
if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ linux ]] && [ -z "$TMUX" ]; then
  exec tmux
fi