+
+###########################
+# Interactive shells only #
+###########################
+
+if [ -z "${PS1}" ]; then
+ return
+fi
+
+
+################
+# Source files #
+################
+
+# Debian/Ubuntu don't source this from /etc/bash.bashrc
+[ -z "$BASH_COMPLETION_VERSINFO" ] && [ -r /usr/share/bash-completion/bash_completion ] && source /usr/share/bash-completion/bash_completion
+
+# This isn't sourced for interactive shells on Debian/Ubuntu/Arch
+# https://bugzilla.gnome.org/show_bug.cgi?id=697475
+[ -r /etc/profile.d/vte.sh ] && source /etc/profile.d/vte.sh
+
+
+################
+# bash options #
+################
+
+# Bash should check the terminal size after every command terminates
+shopt -s checkwinsize
+
+# Don't attempt to tab-complete an empty line
+shopt -s no_empty_cmd_completion
+
+# Prevent overwriting existing files on stdout redirection
+set -o noclobber
+
+# Better history
+shopt -s histappend
+shopt -s cmdhist
+export HISTCONTROL='erasedups:ignoredups:ignorespace'
+export HISTSIZE='100000'
+export HISTTIMEFORMAT='%F %T '
+
+
+###############
+# Pager setup #
+###############
+
+export PAGER='less'
+export LESS='RS'
+
+
+##################
+# Terminal setup #
+##################
+
+# Disable CTRL-s / CTRL-q
+stty -ixon
+
+# Use dark background colors in apps like vim
+export COLORFGBG='15;0'
+
+#############
+# Fancy PS1 #
+#############
+
+# Revision control status for git, hg, svn
+
+function find_up_exists {
+ local d="$PWD"
+ while [ -n "$d" ]; do
+ if [ -e "$d/$1" ]; then
+ return 0
+ fi
+ d="${d%/*}"
+ done
+ return 1
+}
+
+for p in /usr/lib/git-core/git-sh-prompt \
+ /usr/share/git/completion/git-prompt.sh \
+ /usr/share/git-core/contrib/completion/git-prompt.sh \
+ /usr/local/share/git-core/contrib/completion/git-prompt.sh
+do
+ [ -r "$p" ] && source "$p" && break
+done
+
+function my_git_ps1 {
+ find_up_exists .git || return
+ GIT_PS1_SHOWDIRTYSTATE=1 \
+ GIT_PS1_SHOWUNTRACKEDFILES=1 \
+ __git_ps1 ' (%s)' 2> /dev/null
+}
+
+function my_hg_ps1 {
+ find_up_exists .hg || return
+ local status
+ status="$(hg status | cut -c1 | sort -u | tr -d ' \n')"
+ echo -n " ($status)"
+}
+
+function my_svn_ps1 {
+ find_up_exists .svn || return
+ local status
+ status="$(svn status --ignore-externals 2> /dev/null | cut -c1 | sort -u | tr -d ' \n')"
+ [ -n "$status" ] && echo -n " ($status)"
+}
+
+# Two line prompt
+PS1=''
+PS1="$PS1"'\[\e[01;31m\]\u@\h\[\e[00m\]:\[\e[01;34m\]\w\[\e[00m\]'
+PS1="$PS1"'\[\e[01;36m\]$(my_git_ps1 ; my_hg_ps1 ; my_svn_ps1)\[\e[00m\]'
+PS1="$PS1"'\n\$ '
+
+
+#################################
+# Display return codes on error #
+#################################
+
+function print_exit_code {
+ local exit_code="$?"
+ if [ -z "${BASH_SOURCE[1]}" ]; then
+ printf '\e[01;33mexit code: %s\e[00m\n' \
+ "$exit_code"
+ fi
+}
+trap print_exit_code ERR
+
+
+
+####################
+# Function aliases #
+####################
+
+# This prevents long/ugly command lines from showing up in xterm titles
+function aliasf {
+ eval "function $1 { $2 \$@; }"