#
# .zshrc - started by panki on 20200226
#

fpath+=($HOME/.zsh/pure)

autoload -Uz compinit promptinit
autoload -z edit-command-line
zle -N edit-command-line
compinit
promptinit

# fix background color being black...
PS1=${PS1//\%K{black}/%k}

# Return Code on right prompt
RPS1='[%F{yellow}%?%f]'

# history stuff
HISTSIZE=9000
SAVEHIST=9000
setopt appendhistory
bindkey -e

path+=('/home/panki/.local/bin')


# thanks to slashbeast for these ones
# Fancy cd that can cd into parent directory, if trying to cd into file.
# useful with ^F fuzzy searcher.
cd() {
    if (( $+2 )); then
        builtin cd "$@"
        return 0
    fi

    if [ -f "$1" ]; then
        echo "${yellow}cd ${1:h}${NC}" >&2
        builtin cd "${1:h}"
    else
        builtin cd "${@}"
    fi
}

alias sudo='sudo --preserve-env=HOME'
alias grep='grep --colour=auto'
alias diff='diff --color=auto'
alias ls='ls --color=auto'
alias ll='ls -alFh'
alias e='explorer.exe .'
alias nmap='/mnt/c/Program\ Files\ \(x86\)/Nmap/nmap.exe'
alias sudo='sudo '
alias ds='dig +short'
alias kw='date +%V'
lt () { ls -lt ${1} | head }

# define slash and underscore as word separators
WORDCHARS=${WORDCHARS/\/}
WORDCHARS=${WORDCHARS/_}

# vi stuff
if [[ "$(command -v nvim)" ]]; then
    export EDITOR='nvim'
    export MANPAGER='nvim +Man!'
    export MANWIDTH=999
    alias vi='nvim'
    alias vim='vi'
else 
    export EDITOR='vim'
fi

# jump to man flag
function fman () { man -P "less -p \"^ +$2\"" $1 }

# cheat - display text reminders
function cheat() { 
  bat -l md -p ~/cheat/"$1"
}
compdef '_files -W "/home/panki/cheat"' cheat

# tokens etc
test -f "$HOME/.exports" && source "$HOME/.exports"

# wezterm
source "$HOME/.zsh/wezterm.sh"
if [[ $UID -eq 0 ]]; then
  HISTFILE="${HISTFILE%_history}_root_history"
  prompt fade red
else
  HISTFILE=~/.histfile
  prompt pure
  zstyle :prompt:pure:path color green
fi

ICONS=(😈 💀 🤡 👻 👽 👾 🤖 😺 💋 💥 🦥 🐣 🐧 🐸 🐢 🐍 🐳 🌴 🍉 🍎 🍒 🥝 🥥 🥨 🍕 ☕ 🚨 🚀 🛸 🪐 🌠 🌙 🌞 🌈 ⚡ 🔥 💧 ✨ 🎉 💎 💾 📎 💣 📡)
export PURE_PROMPT_SYMBOL="$(shuf -n1 -e "${ICONS[@]}")"
__wezterm_set_user_var "ICON" $PURE_PROMPT_SYMBOL

# local specific
local_conf="$HOME/.zsh/$(hostname).zsh"
test -f $local_conf && source $local_conf
