# If not running interactively, don't do anything
[ -z "$PS1" ] && return

function source-file {
    local file
    file="$1"
    if [[ -f "$file" ]]; then
        # shellcheck disable=SC1090
        source "$file"
    fi
}

if [[ ! "${BASH_VERSION}" = "3.2*" ]]; then
    shopt -s autocd
fi

source-file /etc/bash_completion
source-file ~/.bash/environment
source-file ~/.bash/aliases
source-file ~/.bash/functions
source-file ~/.bash/path
source-file ~/.bash/prompt
source-file ~/.bash/completion
source-file ~/opt/bash/env

unset -f source-file

# append to the history file, don't overwrite it
shopt -s histappend

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

# Disable capslock
if [[ -x $(which setxkbmap) ]]; then
    if [[ $(uname) == Linux ]]; then
        setxkbmap -option ctrl:nocaps
    fi
fi

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && (eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)")
fi

if [ "$TERM" == xterm ]; then
    export TERM=xterm-256color
fi