# The following lines were added by compinstall

zstyle ':completion:*' completer _complete _ignored _correct _approximate
zstyle ':completion:*' expand prefix suffix
zstyle ':completion:*' ignore-parents parent pwd
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'l:|=* r:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' original true
zstyle ':completion:*' preserve-prefix '//[^/]##/'
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' verbose true
zstyle :compinstall filename '/home/wazul/.zshrc'

autoload -Uz compinit
compinit
# End of lines added by compinstall
# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=65536
SAVEHIST=65536
setopt autocd extendedglob
unsetopt beep nomatch notify
bindkey -e
# End of lines configured by zsh-newuser-install

# Dirstack
autoload -Uz add-zsh-hook

DIRSTACKFILE="${XDG_CACHE_HOME:-$HOME/.cache}/zsh/dirs"
if [[ -f "$DIRSTACKFILE" ]] && (( ${#dirstack} == 0 )); then
	dirstack=("${(@f)"$(< "$DIRSTACKFILE")"}")
fi
chpwd_dirstack() {
	print -l -- "$PWD" "${(u)dirstack[@]}" > "$DIRSTACKFILE"
}
add-zsh-hook -Uz chpwd chpwd_dirstack

DIRSTACKSIZE='20'

setopt AUTO_PUSHD PUSHD_SILENT PUSHD_TO_HOME

## Remove duplicate entries
setopt PUSHD_IGNORE_DUPS

## This reverts the +/- operators.
setopt PUSHD_MINUS
# End of dirstack


# Copied from arch wiki:
# create a zkbd compatible hash;
# to add other keys to this hash, see: man 5 terminfo
typeset -g -A key

key[Home]="${terminfo[khome]}"
key[End]="${terminfo[kend]}"
key[Insert]="${terminfo[kich1]}"
key[Backspace]="${terminfo[kbs]}"
key[Delete]="${terminfo[kdch1]}"
key[Up]="${terminfo[kcuu1]}"
key[Down]="${terminfo[kcud1]}"
key[Left]="${terminfo[kcub1]}"
key[Right]="${terminfo[kcuf1]}"
key[PageUp]="${terminfo[kpp]}"
key[PageDown]="${terminfo[knp]}"
key[Shift-Tab]="${terminfo[kcbt]}"

# setup key accordingly
[[ -n "${key[Home]}"      ]] && bindkey -- "${key[Home]}"       beginning-of-line
[[ -n "${key[End]}"       ]] && bindkey -- "${key[End]}"        end-of-line
[[ -n "${key[Insert]}"    ]] && bindkey -- "${key[Insert]}"     overwrite-mode
[[ -n "${key[Backspace]}" ]] && bindkey -- "${key[Backspace]}"  backward-delete-char
[[ -n "${key[Delete]}"    ]] && bindkey -- "${key[Delete]}"     delete-char
[[ -n "${key[Up]}"        ]] && bindkey -- "${key[Up]}"         up-line-or-history
[[ -n "${key[Down]}"      ]] && bindkey -- "${key[Down]}"       down-line-or-history
[[ -n "${key[Left]}"      ]] && bindkey -- "${key[Left]}"       backward-char
[[ -n "${key[Right]}"     ]] && bindkey -- "${key[Right]}"      forward-char
[[ -n "${key[PageUp]}"    ]] && bindkey -- "${key[PageUp]}"     history-beginning-search-backward
[[ -n "${key[PageDown]}"  ]] && bindkey -- "${key[PageDown]}"   history-beginning-search-forward
[[ -n "${key[Shift-Tab]}" ]] && bindkey -- "${key[Shift-Tab]}"  reverse-menu-complete

                               bindkey  "\x1b\x5b\x31\x3b\x33\x44" backward-word # M-Left
                               bindkey  "\x1b\x5b\x31\x3b\x33\x43" forward-word  # M-Right

# Finally, make sure the terminal is in application mode, when zle is
# active. Only then are the values from $terminfo valid.
if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then
	autoload -Uz add-zle-hook-widget
	function zle_application_mode_start { echoti smkx }
	function zle_application_mode_stop { echoti rmkx }
	add-zle-hook-widget -Uz zle-line-init zle_application_mode_start
	add-zle-hook-widget -Uz zle-line-finish zle_application_mode_stop
fi


#
# Custom
#

DEFAULT_PROMPT="%F{green}%n@%m %F{magenta}%~ $ %f"
PROMPT=$DEFAULT_PROMPT

[ -x $HOME/.profile ] && source $HOME/.profile

alias doas='doas '
alias ls='ls --color=auto'
alias tree='tree -C'
alias vim='nvim'
alias mpv='mpv --hwdec=auto'
alias psall='ps aux'
alias linkify='~/git/dotfiles/linkify'
alias fix-chmod='chmod -R ugo-x,u+rwX,go+rX,go-w'
alias reboot-win='sudo efibootmgr -n $(efibootmgr | \grep -m1 -Po "(?<=^Boot)....(?=\* Windows Boot Manager)") && reboot'
alias shu='echo -e ''TURN OFF THE \\e\[1\;31mSPEAKER\\e\[1\;0m NOW!!!''; sleep 3; shutdown now'
alias cal='cal --monday'
alias grep='grep -i --color=always'
alias pwd='pwd -P'
alias gitpullall='~/.selfconfigs/git/git_pull_all'
alias imv-ctl='~/.selfconfigs/imv/imv-ctl'
alias newsboat-recheck='~/.selfconfigs/newsboat/open-nb-unread'
alias denhaag="~/.selfconfigs/etc/denhaag.py"
alias ssh_setup_display='source ~/.selfconfigs/ssh/ssh_setup_display'
alias alawd='swaymsg -- exec alacritty --working-directory \"$(pwd)\"'
alias unfuck-keyboard='echo 2 | sudo tee /sys/module/hid_apple/parameters/fnmode > /dev/null'
alias mv='mv -i'
alias susp='swaylock --image ~/.selfconfigs/sway/lock.png &; systemctl suspend'
alias pacman-remove-orphans="pacman -Rsn \$(pacman -Qdtq)"
alias nope='fc -p $HISTFILE; unset HISTFILE; PROMPT="${PROMPT/$/%F{gray\}$}"'
alias yapp='fc -P; PROMPT=$DEFAULT_PROMPT'
alias magick-webp="magick -define webp:lossless=true"
alias git-list-assume-unchanged="git ls-files -v | \grep '^h'"

# Pentest
alias ssh_single='ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
alias nmap_full='sudo nmap -sS -A -p- -Pn -vv -oN nmap_scan'

if [ -d $HOME/.selfconfigs/zsh/additional.d ] && [ "$(ls -A $HOME/.selfconfigs/zsh/additional.d)" ]; then
	for f in $HOME/.selfconfigs/zsh/additional.d/*; do source $f; done
fi

if [ -d $HOME/.selfconfigs/zsh/functions ] && [ "$(ls -A $HOME/.selfconfigs/zsh/functions)" ]; then
       	autoload -Uz $HOME/.selfconfigs/zsh/functions/*
fi

if [ -z $DISPLAY ] && [ "$(tty)" = "/dev/tty1" ]; then
	sway
elif [[ -o login ]] && ! [[ -f $HOME/.selfconfigs/zsh/disable_motd ]]; then
	cat $HOME/.selfconfigs/zsh/motd
fi

if [[ $1 == "newsboat" ]]; then
	"$HOME"/.selfconfigs/newsboat/open-nb-unread
fi

if [[ $TERM == "screen" ]]; then
	echo "Screen terminal started: $STY"
fi