shopt -s cdspell             # correct spelling for directories
shopt -s checkwinsize        # Check columns and lines window size after every run
shopt -s extglob             #
shopt -s nocaseglob;         # Case-insensitive globbing (used in pathname expansion)
shopt -s histverify          # Don't run history substitution immediately (!!), require confirmation

shopt -s cmdhist    # Save multi-line commands as one command
shopt -s histappend # Append history across shells
export HISTCONTROL=ignoreboth:erasedups # Ignore duplicates in the history and commands starting with space
export HISTSIZE=500000
export HISTFILESIZE=100000
export HISTTIMEFORMAT='%F %T - '

# Simple prompt coloring
PS1="$(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]\h'; else echo '\[\033[01;32m\]\u@\h'; fi)\[\033[01;34m\] \w \$([[ \$? != 0 ]] && echo \"\[\033[01;31m\]:(\[\033[01;34m\] \")\\$\[\033[00m\] "

if [[ "$(set -o | grep 'emacs\|\bvi\b' | cut -f2 | tr '\n' ':')" != 'off:off:' ]];
then
  bind Space:magic-space                # Enable history expansion with space e.g. !!<space> will replace the !! with your last command
  bind 'set completion-ignore-case on'  # Perform file completion in a case insensitive fashion
  bind 'set completion-map-case on'     # Treat hyphens and underscores as equivalent

  # The following allows partial searching (e.g. ss<up|down> will autocomplete ssh 4.2.2.2)
  bind '"\e[A": history-search-backward'
  bind '"\e[B": history-search-forward'
  bind '"\e[C": forward-char'
  bind '"\e[D": backward-char'
fi
