# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=10000
SAVEHIST=10000

setopt appendhistory
setopt incappendhistory
setopt sharehistory
setopt histignoredups
setopt histignorespace
setopt histreduceblanks
setopt autocd nomatch

unsetopt beep extendedglob notify
bindkey -e

## stillOS additions
if (( EUID == 0 )); then
  PROMPT='%B%F{red}%n%f // %F{red}%~%f >>%b '
else
  PROMPT='%B%F{blue}%n%f // %F{cyan}%~%f >>%b '
fi

# plugins (still-zsh bundled)
if [ -d /usr/share/still-zsh/plugins ]; then
  source /usr/share/still-zsh/plugins/git-prompt/git-prompt.plugin.zsh
  source /usr/share/still-zsh/plugins/copyfile.plugin.zsh
  source /usr/share/still-zsh/plugins/copypath.plugin.zsh
  [[ -f /usr/share/still-zsh/plugins/colors.plugin.zsh ]] && source /usr/share/still-zsh/plugins/colors.plugin.zsh
  [[ -f /usr/share/still-zsh/plugins/colorize.plugin.zsh ]] && source /usr/share/still-zsh/plugins/colorize.plugin.zsh
  [[ -f /usr/share/still-zsh/plugins/zsh-z/zsh-z.plugin.zsh ]] && source /usr/share/still-zsh/plugins/zsh-z/zsh-z.plugin.zsh
  [[ -f /usr/share/still-zsh/plugins/web-search.plugin.zsh ]] && source /usr/share/still-zsh/plugins/web-search.plugin.zsh
  [[ -f /usr/share/still-zsh/plugins/autoswitch_virtualenv.plugin.zsh ]] && source /usr/share/still-zsh/plugins/autoswitch_virtualenv.plugin.zsh
  [[ -f /usr/share/still-zsh/plugins/extract/extract.plugin.zsh ]] && source /usr/share/still-zsh/plugins/extract/extract.plugin.zsh
fi

if [ -d /usr/share/zsh-autosuggestions ]; then
  source /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh
fi

# syntax highlighting last (separate package)
if [ -d /usr/share/zsh-fast-syntax-highlighting ]; then
  source /usr/share/zsh-fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
fi

autoload -Uz compinit
compinit

# Plugin Credits (some are slightly modified):
# copyfile, copypath (modified for Wayland): https://github.com/ohmyzsh/ohmyzsh
# git-prompt, web-search, extract: https://github.com/ohmyzsh/ohmyzsh
# colors: https://github.com/zpm-zsh/colors | colorize: https://github.com/zpm-zsh/colorize
# zsh-z: https://github.com/agkozak/zsh-z
# autoswitch_virtualenv: https://github.com/MichaelAquilina/zsh-autoswitch-virtualenv
# zsh-autosuggestions: https://github.com/zsh-users/zsh-autosuggestions
# zsh-fast-syntax-highlighting (package): https://github.com/zdharma-continuum/fast-syntax-highlighting

# aliases
alias rm=rm -i

# binds
zmodload zsh/terminfo 2>/dev/null
autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
autoload -Uz edit-command-line
zle -N edit-command-line
bindkey "^X^E" edit-command-line

[[ -n "${terminfo[kdch1]}" ]] && bindkey "${terminfo[kdch1]}" delete-char
[[ -n "${terminfo[kich1]}" ]] && bindkey "${terminfo[kich1]}" overwrite-mode
[[ -n "${terminfo[khome]}" ]] && bindkey "${terminfo[khome]}" beginning-of-line
[[ -n "${terminfo[kend]}" ]] && bindkey "${terminfo[kend]}" end-of-line
[[ -n "${terminfo[kpp]}" ]] && bindkey "${terminfo[kpp]}" history-beginning-search-backward
[[ -n "${terminfo[knp]}" ]] && bindkey "${terminfo[knp]}" history-beginning-search-forward
[[ -n "${terminfo[kcuu1]}" ]] && bindkey "${terminfo[kcuu1]}" up-line-or-beginning-search
[[ -n "${terminfo[kcud1]}" ]] && bindkey "${terminfo[kcud1]}" down-line-or-beginning-search

bindkey "^[[3~" delete-char
bindkey "^[[2~" overwrite-mode
bindkey "^[[H" beginning-of-line
bindkey "^[[F" end-of-line
bindkey "^[OH" beginning-of-line
bindkey "^[OF" end-of-line
bindkey "^[[5~" history-beginning-search-backward
bindkey "^[[6~" history-beginning-search-forward
bindkey "^[[A" up-line-or-beginning-search
bindkey "^[[B" down-line-or-beginning-search
bindkey "^[[Z" reverse-menu-complete
bindkey "^[[1;5C" forward-word
bindkey "^[[1;5D" backward-word
bindkey "^[[5C" forward-word
bindkey "^[[5D" backward-word
bindkey "^[OC" forward-word
bindkey "^[OD" backward-word
bindkey "^[[3;5~" kill-word
export EDITOR=micro

# still-fetch
[[ -o interactive && -t 1 ]] && command -v still-fetch >/dev/null && still-fetch
