#!/bin/sh

pfetch

eval "$(starship init zsh)"

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

zstyle ':completion:*' rehash true

# Plugins
plug "kutsan/zsh-system-clipboard"
plug "hlissner/zsh-autopair"
plug "zap-zsh/supercharge"
plug "zap-zsh/completions"
plug "zap-zsh/vim"
plug "zsh-users/zsh-autosuggestions"
plug "zsh-users/zsh-completions"
plug "chivalryq/git-alias"
plug "zdharma-continuum/fast-syntax-highlighting"
plug "zsh-users/zsh-history-substring-search"
plug "MichaelAquilina/zsh-you-should-use"

# Startup zoxide
eval "$(zoxide init zsh)"

# Substring search settings
export HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND="bg=blue,fg=black,bold"
export HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND='bg=red,fg=black,bold'
bindkey -M vicmd 'k' history-substring-search-up
bindkey -M vicmd 'j' history-substring-search-down

# Plugin settings
if [ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then
    ZSH_SYSTEM_CLIPBOARD_METHOD="xsc"
else
    ZSH_SYSTEM_CLIPBOARD_METHOD="wlc"
fi

# Local source
plug "$XDG_CONFIG_HOME/zsh/aliases.zsh"
plug "$XDG_CONFIG_HOME/zsh/functions.zsh"

# History settings
setopt appendhistory
setopt INC_APPEND_HISTORY
export HISTTIMEFORMAT="[%F %T]"

HISTFILE="$XDG_STATE_HOME"/zsh/history

[ -n "$NNNLVL" ] && PS1="N$NNNLVL $PS1"

nnn_cd ()
{
    if ! [ -z "$NNN_PIPE" ]; then
        printf "%s\0" "0c${PWD}" > "${NNN_PIPE}" !&
    fi
}

trap nnn_cd EXIT

# Check if in tmux and if a venv directory exists activate the python environment
if [ ! -z "$TMUX" ] && [ -d "./env" ]; then
    . ./env/bin/activate
fi