# Set up the prompt
# See PS1 below
#autoload -Uz promptinit
#promptinit
#prompt adam1
#prompt adam2 
#prompt fire
#prompt bart
#prompt elite2
#prompt default

# Taken from Kali Linux .zshrc 
# --------- KALI -------------
setopt autocd              # change directory just by typing its name
#setopt correct            # auto correct mistakes
setopt interactivecomments # allow comments in interactive mode
setopt magicequalsubst     # enable filename expansion for arguments of the form ‘anything=expression’
setopt nonomatch           # hide error message if there is no match for the pattern
setopt notify              # report the status of background jobs immediately
setopt numericglobsort     # sort filenames numerically when it makes sense
setopt promptsubst         # enable command substitution in prompt

# configure key keybindings
# Use emacs keybindings even if our EDITOR is set to vi
#bindkey -e                                        # emacs key bindings
#bindkey ' ' magic-space                           # do history expansion on space
#bindkey '^U' backward-kill-line                   # ctrl + U
#bindkey '^[[3;5~' kill-word                       # ctrl + Supr
#bindkey '^[[3~' delete-char                       # delete
#bindkey '^[[1;5C' forward-word                    # ctrl + ->
#bindkey '^[[1;5D' backward-word                   # ctrl + <-
#bindkey '^[[5~' beginning-of-buffer-or-history    # page up
#bindkey '^[[6~' end-of-buffer-or-history          # page down
#bindkey '^[[H' beginning-of-line                  # home
#bindkey '^[[F' end-of-line                        # end
#bindkey '^[[Z' undo                               # shift + tab undo last action

# History configurations
HISTFILE=~/.zsh_history
HISTSIZE=1000
SAVEHIST=2000
setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE
setopt hist_ignore_dups       # ignore duplicated commands history list
setopt hist_ignore_space      # ignore commands that start with space
setopt hist_verify            # show command with history expansion to user before running it
#setopt share_history         # share command history data

# force zsh to show the complete history
alias history="history 0"
# --------- KALI -------------

setopt histignorealldups sharehistory

# Do not ask for confirmation when deleting * or dir/* 
#setopt localoptions rmstarsilent

# Keep 1000 lines of history within the shell and save it to ~/.zsh_history:
HISTSIZE=1000
SAVEHIST=1000
HISTFILE=~/.zsh_history

# Use modern completion system
autoload -Uz compinit
compinit

zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
eval "$(dircolors -b)"
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true

zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'

zstyle ':completion:*' menu select=0
#zstyle ':completion:*' menu select=2


# ---------------------------------------
# zplug - manage plugins
source /usr/share/zplug/init.zsh
#zplug "junegunn/fzf"
#zplug "plugins/git", from:oh-my-zsh
#zplug "plugins/ufw", from:oh-my-zsh
#zplug "plugins/docker", from:oh-my-zsh
#zplug "plugins/debian", from:oh-my-zsh
#zplug "plugins/systemadmin", from:oh-my-zsh
#zplug "plugins/colored-man-pages", from:oh-my-zsh
zplug "zsh-users/zsh-syntax-highlighting"
zplug "zsh-users/zsh-autosuggestions"
zplug "zsh-users/zsh-history-substring-search"
zplug "zsh-users/zsh-completions"
zplug "plugins/sudo", from:oh-my-zsh
zplug "plugins/command-not-found", from:oh-my-zsh
#zplug "plugins/extract", from:oh-my-zsh
#zplug "plugins/rsync", from:oh-my-zsh
#zplug "plugins/screen", from:oh-my-zsh

# zplug - install/load new plugins when zsh is started or reloaded
if ! zplug check --verbose; then
    printf "Install? [y/N]: "
    if read -q; then
        echo; zplug install
    fi
fi
#zplug load --verbose
zplug load 

# ---------------------------------------
# My own stuff 
alias ls='ls --color=auto'
alias l='ls -lh'
alias ll='ls -lha'
alias df='df -h'
alias free='free -mth --si'
alias ip='ip --color=auto'
alias diff='diff --color=auto'
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias saveKDESession='qdbus org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.saveCurrentSession'
alias gitlog="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %    C(bold blue)<%an>%Creset' --abbrev-commit "
alias gitlscommit="git diff-tree --no-commit-id --name-only -r HEAD"

# Custom commands
if [ -x "$(which htop)" ]; then
    alias top='htop'
fi

if [ -x "$(which vim)" ]; then
    alias vi='vim'
fi

if [ -x "$(which neofetch)" ]; then
    if [ -f ~/.neofetch.rc ]; then
        alias neofetch='neofetch --config ~/.neofetch.rc '
    else
        alias neofetch='neofetch  --cpu_cores logical  --cpu_speed on --cpu_temp on --distro_shorthand off --kernel_shorthand off --uptime_shorthand off --gpu_brandon --gpu_type all --de_version on --gkt-shorthand off --gtk2 on--gtk3 on --shell_path on --shell_version on --disk_percent on --memory_percent on --color_blocks off --bold on --ascii_bold on --ascii_distro debian'
    fi
fi

if [ -x "$(which batcat)" ]; then
    alias cat='batcat -p'
fi

if [ -x "$(which exa)" ]; then
    alias ls='exa --icons --git --group '
    alias l='ls -l -H'
    alias ll='ls -la -H'

    #alias tree='exa --tree --icons --git'
    function mytree () {
        if [[ $1 =~ '^[0-9]+$' ]]; then
            lvl="$1"
            shift 
        else
            lvl="1"
        fi
        #echo "Level: $lvl"
        exa --tree --level=$lvl --icons --git $@
    }
    alias tree='mytree' 
fi

# load GIT stuff 
if [ -f .git-prompt.sh ]; then
    source .git-prompt.sh 
fi

if [ -f .git-completion.zsh ]; then
    source ~/.git-completion.zsh
fi

# For trustworthy copies. Be aware of SRC/ DST/ x SRC DST/ 
alias rsyncNoDelete='rsync --archive --perms --owner --group --copy-devices --specials --times --atimes --open-noatime --links --verbose --recursive --update --progress '
alias rsyncWithDeleteTest='rsync --dry-run --itemize-changes --archive --perms --owner --group --copy-devices --specials --times --atimes --open-noatime --links --verbose --recursive --delete --delete-excluded --update --progress '
alias rsyncWithDelete='rsync --archive --perms --owner --group --copy-devices --specials --times --atimes --open-noatime --links --verbose --recursive --delete --delete-excluded --update --progress '

# Run programs using Nvidia discreet card (Debian 11 and above)
alias nvidia-run='__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia '

# Key bindings
bindkey '^H' backward-kill-word

# Make Esc+Backspace work as in Bash ;)
# These chars will be erased together with words.
#export WORDCHARS='*?_-.[]~=&;!#$%^(){}<>'
export WORDCHARS='*?_-[]~=&;!#$%^(){}<>'

# Hide the EOL char ('%') at the end of lines
PROMPT_EOL_MARK=""

# ----------
# IMPORTANT!
# ----------
# Do not use " with your PS1 or things like vcs_info will NOT work! 
# Prefer using ' for the PS1 varialbe. See example below.
# Last checked on: Mon 12 Dec 2022 10:03:41 PM EST

# Version control (GIT)
# Enable VCS (GIT,SVN) support
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git svn
precmd() {
    vcs_info
}

setopt prompt_subst
zstyle ':vcs_info:git*' formats '%F{magenta}%s<%f%F{yellow}%b%f%F{magenta}>[%f%F{yellow}%a %m%u%c%f%F{magenta}]%f'
# This may slow things a bit
#zstyle ':vcs_info:*' check-for-changes true  

clear
unset PS1
# This will make a fancy prompt with stats about your session.
#NEWLINE=$'\n'
#TOPBAR="----------------------------------------------------------------"
#MIDBAR="| Line:%y | Jobs:%j | SHLVL:%L | Return:%? | %D{%d %b %Y} %T |"
#BOTBAR="----------------------------------------------------------------"
#PS1STR="${TOPBAR}${NEWLINE}${MIDBAR}${NEWLINE}${BOTBAR}${NEWLINE}"
#PS1='${PS1STR}%B%F{yellow}[%f%F{green}%n%f%F{yellow}@%f%F{blue}%m%f ${vcs_info_msg_0_} %F{white}%~%f%F{yellow}]%f %F{red}%(!.#.$)%f%b '

# This is justa fancy promptp without stats. Just VCS integration and FULL path
#PS1='%B%F{yellow}[%f%F{green}%n%f%F{yellow}@%f%F{blue}%m%f ${vcs_info_msg_0_} %F{white}%~%f%F{yellow}]%f %F{red}%(!.#.$)%f%b '

# This is justa fancy promptp without stats. Just VCS integration and RELATIVE path
PS1='%B%F{yellow}[%f%F{green}%n%f%F{yellow}@%f%F{blue}%m%f ${vcs_info_msg_0_} %F{white}%1~%f%F{yellow}]%f %F{red}%(!.#.$)%f%b '

export PS1

# Include user's bin directory
if [ -d ~/bin ]; then
    export PATH=$PATH:~/bin
fi

if [ -d ~/.local/bin ]; then
    export PATH=$PATH:~/.local/bin
fi

# AppImage binaries
if [ -d ~/AppImage ]; then
    export PATH=$PATH:~/AppImage
fi

# Custom aliases
if [ -f .zsh_aliases ]; then
    source .zsh_aliases
fi


