# z shell configuration

PROMPT="%F{green}%~ %F{yellow}%m %f"

bindkey -e

# zstyles
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*' menu no

# hist
HISTFILE="$HOME/.local/share/zsh_hist"
HISTSIZE=10000000
SAVEHIST=$HISTSIZE

setopt appendhistory
setopt sharehistory
setopt hist_save_no_dups
setopt hist_ignore_all_dups
setopt hist_find_no_dups
setopt hist_ignore_space

# shell alias
alias ls="ls -h --color=auto"
alias la="ls -ah --color=auto"
alias ll="ls -ahl --color=auto"

# env vars
export GOPATH="$HOME/.local/share/go"
export PATH="$PATH:$GOPATH/bin"

export EDITOR="nvim"

# functions
func calc() {
  # why isn't this in bash by default
  #
  if command -v python3 > /dev/null; then
    python3 -c "print($1)"
  else
    echo "python3 needs to be installed for this to work!"
  fi
}

# plugins
plugindir="$HOME/.local/share/zsh_plug"
func plugInstall() {
  # clones a repo and then sources it.
  # first arg is git url, second is source
  # location
  
  foldername=$(basename $1)
  clonepath="$plugindir/$foldername"
  sourcefile="$clonepath/$2"

  if command -v git > /dev/null && [ ! -d "$clonepath" ]; then
    git clone $1 "$clonepath" --depth=1
  fi

  if [ -f "$sourcefile" ]; then
    source "$sourcefile"
  fi
}

plugInstall https://github.com/zsh-users/zsh-syntax-highlighting zsh-syntax-highlighting.zsh
plugInstall https://github.com/Aloxaf/fzf-tab fzf-tab.zsh

# load fzf and zoxide
eval "$(fzf --zsh)"
eval "$(zoxide init zsh)"
