# ~/.bashrc: executed by bash(1) for interactive non-login shells.

# If not running interactively, don't do anything.
case $- in
    *i*) ;;
      *) return ;;
esac

# Don't put duplicate lines or lines starting with a space in the history.
HISTCONTROL=ignoreboth

# Append to the history file instead of overwriting it.
shopt -s histappend

HISTSIZE=1000
HISTFILESIZE=2000

# Update LINES and COLUMNS after each command.
shopt -s checkwinsize

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

# Set variable identifying the chroot, if present.
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# Detect actual terminal color capability.
color_prompt=

if [ -t 1 ] && command -v tput >/dev/null 2>&1; then
    colors="$(tput colors 2>/dev/null || echo 0)"

    case "$colors" in
        ''|*[!0-9]*) colors=0 ;;
    esac

    if [ "$colors" -ge 8 ]; then
        color_prompt=yes
    fi
fi

if [ "$color_prompt" = yes ]; then
    if [ "$(id -u)" -eq 0 ]; then
        # Root: red user@host, blue working directory.
        PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    else
        # Normal user: green user@host, blue working directory.
        PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    fi
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi

unset color_prompt colors

# Set xterm-compatible terminal title to user@host:dir.
case "$TERM" in
    xterm*|rxvt*|screen*|tmux*)
        PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
        ;;
esac

if command -v dircolors >/dev/null 2>&1; then
    if [ -r "$HOME/.dircolors" ]; then
        eval "$(dircolors -b "$HOME/.dircolors")"
    else
        eval "$(dircolors -b)"
    fi

    alias ls='ls --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# Ubuntu/Debian-style ls aliases.
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

if [ -f "$HOME/.bash_aliases" ]; then
    . "$HOME/.bash_aliases"
fi

if ! shopt -oq posix; then
    if [ -r /usr/share/bash-completion/bash_completion ]; then
        . /usr/share/bash-completion/bash_completion
    elif [ -r /etc/bash_completion ]; then
        . /etc/bash_completion
    fi
fi
