#!/bin/bash - not strictly necessary, but helps nano with syntax highlighting.
# Bash specific configuration.

__prompt_user_colour() {
  # Determine the colour of the username in the prompt.

  if [[ "$(whoami)" == "root" ]]; then
    printf "%s" "1;31m"		# Bright Red.
  elif [[ "$(whoami)" == "tadgy" ]]; then
    printf "%s" "1;32m"		# Bright Green.
  else
    printf "%s" "1;36m"		# Bright Cyan.
  fi

  return 0
}

shopt -s cdspell checkhash checkjobs checkwinsize cmdhist dirspell histappend no_empty_cmd_completion

HISTCONTROL="ignoredups"
HISTFILE="$HOME/.bash_history-${HOSTNAME%%.*}"
HISTFILESIZE=1000000
HISTIGNORE="bg:bg *:fg:fg *:jobs:exit:clear:history"
HISTSIZE=1000000
HISTTIMEFORMAT="%d/%m/%y %H:%M:%S  "
IGNOREEOF=0
PROMPT_DIRTRIM=2
PS1='[\[\033[$(__prompt_user_colour)\]\u\[\033[0m\]@\[\033[1;33m\]\h\[\033[0m\]] \[\033[1;34m\]\w\[\033[0m\] ->'

history -a
history -r

hash grep >/dev/null 2>&1 && { alias egrep='grep -E'; alias fgrep='grep -F'; }
hash ps grep >/dev/null 2>&1 && psgrep() {
  if [[ -n "$1" ]]; then
    # shellcheck disable=SC2009
    ps -auwwx | command grep -E -- "(.*RSS.*|$1)" | command grep -F -v '(.*RSS.*|'
  else
    printf "%s: %s\\n" "Usage" "${FUNCNAME[0]} <something>" >&2
    return 1
  fi
}
hash ls >/dev/null 2>&1 && alias ls='ls -Fv --color=always'
hash nc >/dev/null 2>&1 && alias pastebin='nc termbin.com 9999'

for FILE in "$HOME"/.bashrc.d/*; do
  [[ -x "$FILE" ]] && source "$FILE"
done
unset FILE
