# ~/.bashrc
#

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

HISTCONTROL=ignoreboth # don't put duplicate lines or lines starting with space in the history.
shopt -s histappend # append to the history file, don't overwrite it
HISTSIZE=10000
HISTFILESIZE=10000

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi

# On Arch Linux, source pkgfile "command not found" hook
if [ -e /usr/share/doc/pkgfile/command-not-found.bash ]; then
    . /usr/share/doc/pkgfile/command-not-found.bash
fi

# Enable colored less output
export LESS_TERMCAP_mb=$'\e[1;32m'
export LESS_TERMCAP_md=$'\e[1;32m'
export LESS_TERMCAP_me=$'\e[0m'
export LESS_TERMCAP_se=$'\e[0m'
export LESS_TERMCAP_so=$'\e[01;33m'
export LESS_TERMCAP_ue=$'\e[0m'
export LESS_TERMCAP_us=$'\e[1;4;31m'

# enable exit status in prompt command
PROMPT_COMMAND=__prompt_command

__prompt_command() {
    local EXIT="$?"
    PS1=""

    local RCol='\[\e[0m\]'

    local Red='\[\e[0;31m\]'
    local Gre='\[\e[0;32m\]'
    local BYel='\[\e[1;33m\]'
    local BBlu='\[\e[1;34m\]'
    local Pur='\[\e[0;35m\]'

    if [ $EXIT != 0 ]; then
        PS1+="${Red}\u${RCol}"
    else
        PS1+="${Gre}\u${RCol}"
    fi

    PS1+="${RCol}@${BBlu}\h${RCol}:${Pur}\w${RCol}$ ${RCol}"
}

# Enable bash-git-prompt
if [ -f "$HOME/.bash-git-prompt/gitprompt.sh" ]; then
    GIT_PROMPT_ONLY_IN_REPO=1
    GIT_PROMPT_SHOW_UPSTREAM=1
    GIT_PROMPT_THEME=Plague_Doctor
    source ~/.bash-git-prompt/gitprompt.sh
fi

if [ -e /usr/lib/python3*/site-packages/argcomplete ] || pip show argcomplete >/dev/null 2>&1; then
    eval "$(register-python-argcomplete schedule-timer acnt)"
fi

case "$TERM" in
    xterm-kitty) source <(kitty + complete setup bash);;
esac

stty -ixon # Disable Ctrl-S and Ctrl-Q