#
# ~/.bashrc -- Sourced by bash in interactive non-login shells; includes ~/bashrc.d/* and ~/.bashrc.local
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

# Bash settings
set -o noclobber
shopt -s checkwinsize
shopt -s histappend
export HISTCONTROL=ignoreboth
export HISTSIZE=1000
export HISTFILESIZE=2000
export PROMPT_DIRTRIM=3

# Color output and default options
export GREP_OPTS='--color=auto'
export LS_OPTS='--color=auto -hFN --group-directories-first'
export LESS="-Ri"

# colored GCC warnings and errors
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# Set default options
alias ls='ls ${LS_OPTS}'
alias grep='grep ${GREP_OPTS}'
alias diff='diff --color=auto'
alias ip='ip -color=auto'

# Common shortcut aliases
alias l='ls -l'
alias la='ls -a'
alias ll='ls -la'

# Colored man pages
man() {
	env \
		LESS_TERMCAP_mb=$(printf "\e[1;31m") \
		LESS_TERMCAP_md=$(printf "\e[1;31m") \
		LESS_TERMCAP_me=$(printf "\e[0m") \
		LESS_TERMCAP_se=$(printf "\e[0m") \
		LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
		LESS_TERMCAP_ue=$(printf "\e[0m") \
		LESS_TERMCAP_us=$(printf "\e[1;32m") \
	man "$@"
}

# (Other aliases are defined in .bashrc.d/10_common_aliases.sh etc.)

# Load z
[[ -r "/usr/share/z/z.sh" ]] && source /usr/share/z/z.sh

# Define colors for bash prompt (will also be used in .bashrc.local)
   TRED='\[\e[0;31m\]'  # Red
 TGREEN='\[\e[0;32m\]'  # Green
  TBLUE='\[\e[0;34m\]'  # Blue
TGREENB='\[\e[1;32m\]'  # Green bold
 TCYANB='\[\e[1;36m\]'  # Cyan bold
TWHITEB='\[\e[1;37m\]'  # White bold
 TRESET='\[\e[0m\]'     # Text Reset

# Set default prompt
if [[ ${EUID} == 0 ]] ; then
	PS1="${TRED}\u@\h ${TBLUE}\w ${TWHITEB}\$ ${TRESET}"
else
	PS1="${TGREEN}\u@\h ${TBLUE}\w ${TWHITEB}\$ ${TRESET}"
fi

# Include drop-in files
if [[ -d ~/.bashrc.d ]]; then
	for f in ~/.bashrc.d/*; do
		[[ -f $f ]] && source "$f"
	done
fi

# Include host-specific bashrc
[[ -f ~/.bashrc.local ]] && source ~/.bashrc.local

# Clean up environment variables
unset TRED TGREEN TBLUE TGREENB TCYANB TWHITEB TRESET
