--- /dev/null
+#! bash
+
+# This file is responsible for setting up the pretty colours in GNU 'ls' and
+# the bash prompt. It also sets COLORFGBG to give programs like vim an idea
+# of the terminal colours to use. If your terminal isn't detected correctly
+# then you can run lightterm or darkterm to get the colours right. To do this
+# automatically try changing the table below.
+
+# Terminals that we want coloured prompts in
+[ -n "$COLORTERM" ] && PS1_COLOR=1
+[ "$TERM" = "linux" ] && PS1_COLOR=1 && DARK=1
+[ "$TERM" = "screen" ] && PS1_COLOR=1
+[ "$TERM" = "xterm" ] && PS1_COLOR=1
+[ "$TERM" = "xterm-color" ] && PS1_COLOR=1
+[ "$TERM" = "rxvt" ] && PS1_COLOR=1
+[ "$TERM" = "rxvt-unicode" ] && PS1_COLOR=1
+
+# Use colours appropriate to a light on dark terminal, we can autodetect
+# this for some terminals, for others we define it above.
+if [ -n "$COLORFGBG" ]; then
+ FGCOLOR=$(echo $COLORFGBG | cut -d ';' -f 1)
+ BGCOLOR=$(echo $COLORFGBG | cut -d ';' -f 3)
+ if [ "$FGCOLOR" -gt "$BGCOLOR" ]; then
+ DARK=1
+ fi
+ unset FGCOLOR
+ unset BGCOLOR
+elif [ ${DARK:-0} -eq 0 ]; then
+ export COLORFGBG="0;default;15"
+elif [ ${DARK:-0} -eq 1 ]; then
+ export COLORFGBG="15;default;0"
+fi
+
+# Set the prompt colour, and the colors for the 'ls' command appropriately,
+# depending on the background of the terminal.
+if [ ${PS1_COLOR:-0} -eq 1 ]; then
+ LS_COLORS='no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:do=00;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.deb=00;31:*.rpm=00;31:*.jar=00;31:*.jpg=00;35:*.jpeg=00;35:*.gif=00;35:*.bmp=00;35:*.pbm=00;35:*.pgm=00;35:*.ppm=00;35:*.tga=00;35:*.xbm=00;35:*.xpm=00;35:*.tif=00;35:*.tiff=00;35:*.png=00;35:*.mov=00;35:*.mpg=00;35:*.mpeg=00;35:*.avi=00;35:*.fli=00;35:*.gl=00;35:*.dl=00;35:*.xcf=00;35:*.xwd=00;35:*.flac=00;35:*.mp3=00;35:*.mpc=00;35:*.ogg=00;35:*.wav=00;35:'
+ PS1='\[\033[00;31m\]\u@\h\[\033[00m\]:\[\033[00;34m\]\w\[\033[00m\]\$ '
+
+ if [ ${DARK:-0} -eq 1 ]; then
+ # We need to bold the LS_COLORS and PS1 environment variables
+ # so they show up on a dark terminal
+ LS_COLORS="$(echo "${LS_COLORS}" | sed 's/00;/01;/g')"
+ PS1="$(echo "${PS1}" | sed 's/00;/01;/g')"
+ fi
+
+ export LS_COLORS
+ unset PS1_COLOR
+ unset DARK
+fi
+
--- /dev/null
+#! bash
+
+# This file sets up the environment correctly. It gets run for every shell,
+# so it must be fast. Also, starting a shell within a shell shouldn't change
+# the environment. The path manipulation functions are useful for this.
+
+# Files will be created by default rwx user only
+umask 0077
+
+# General environment settings
+export PAGER="less"
+export EDITOR="vim"
+export CVS_RSH="ssh"
+export RSYNC_RSH="ssh"
+export PYTHONSTARTUP="${HOME}/.pythonrc.py"
+export HISTCONTROL="ignoredups"
+export HISTSIZE="10000"
+
+# Load the bash functions
+source "${HOME}/.bash/functions"
+
+# The current directory shouldn't be in the path
+pathremove .
+
+# Load local environment settings
+ssource "${HOME}/.bash/environment_local"
+
+# ~/bin should be in the front of path if it exists
+pathprepend "${HOME}/bin"
+
--- /dev/null
+#! bash
+
+# Useful bash functions. This is sourced by the environment file.
+# These are available to scripts, but you shouldn't use them in scripts if you
+# want them to be portable.
+
+
+# Usage: pathremove /path/to/bin [PATH]
+# Eg, to remove ~/bin from $PATH
+# pathremove ~/bin PATH
+pathremove() {
+ local IFS=':'
+ local NEWPATH
+ local DIR
+ local PATHVARIABLE=${2:-PATH}
+ for DIR in ${!PATHVARIABLE} ; do
+ if [ "${DIR}" != "${1}" ] ; then
+ NEWPATH="${NEWPATH:+${NEWPATH}:}${DIR}"
+ fi
+ done
+ export ${PATHVARIABLE}="${NEWPATH}"
+}
+
+# Usage: pathprepend /path/to/bin [PATH]
+# Eg, to prepend ~/bin to $PATH
+# pathprepend ~/bin PATH
+pathprepend() {
+ pathremove "${1}" "${2}"
+ [ -d "${1}" ] || return
+ local PATHVARIABLE="${2:-PATH}"
+ export ${PATHVARIABLE}="${1}${!PATHVARIABLE:+:${!PATHVARIABLE}}"
+}
+
+# Usage: pathappend /path/to/bin [PATH]
+# Eg, to append ~/bin to $PATH
+# pathappend ~/bin PATH
+pathappend() {
+ pathremove "${1}" "${2}"
+ [ -d "${1}" ] || return
+ local PATHVARIABLE=${2:-PATH}
+ export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}${1}"
+}
+
+# Usage: ssource /path/to/shellscript
+# Checks if the file exists before sourcing it
+ssource() {
+ [ -r "${1}" ] && source "${1}"
+}
+
+# Sets colours to be appropriate for a light on dark terminal
+darkterm() {
+ DARK=1
+ source "${HOME}/.bash/colors"
+}
+
+# Sets the colours to be appropriate for a dark on light terminal
+lightterm() {
+ DARK=0
+ source "${HOME}/.bash/colors"
+}
+
+# Usage: mcd somedir
+# Creates the directory if it doesn't exist, and changes into it
+mcd() {
+ mkdir -p "${1}" &&
+ cd "${1}"
+}
+
+
+# Load local functions
+ssource "${HOME}/.bash/functions_local"
+
--- /dev/null
+#! bash
+
+# Sets up the shell for interactive commands
+
+# xterm titlebar displays current command
+case "${TERM}" in
+xterm*|rxvt*)
+ HOSTNAME="$(hostname | cut -d '.' -f 1)"
+ CWD_WITHHOME='"$(echo "${PWD}" | sed "s|^${HOME}|~|")"'
+ PROMPT_COMMAND="echo -ne \"\033]0;${HOSTNAME}: ${CWD_WITHHOME}\007\""
+ unset HOSTNAME
+ ;;
+*)
+ ;;
+esac
+
+# Prompt: user@host:directory$
+PS1='\u@\h:\w\$ '
+
+# Useful aliases
+alias ls='ls --color=auto'
+alias ll='ls -hlF'
+alias la='ls -ha'
+alias l='ls -halF'
+alias rm='rm -i'
+alias less='less -R'
+alias screen='TERM=xterm screen'
+
+# Bash should check the terminal size after every command terminates
+shopt -s checkwinsize
+
+# The all important colours!
+ssource "${HOME}/.bash/colors"
+
+# Local customisations
+ssource "${HOME}/.bash/interactive_local"
+
--- /dev/null
+#! bash
+
+# Is run whenever we have a login interactive shell. Just prints a little
+# welcome message.
+
+echo "Welcome to $(uname)"
+if which fortune &> /dev/null; then
+ echo $(fortune -s)
+ echo
+fi
+
+ssource "${HOME}/.bash/login_local"
+
-# Run for login shells. That is, once when you log in via SSH this is run
-# to set up your environment variables such as PATH, etc. It then calls
-# .bashrc to set up aliases or prompts.
-# Copy this around to all your machines and make machine specific
-# customisations to ~/.bash_profile_local
-
-unset RUN_BASH_PROFILE
-
-# Source the global profile
+# Pull in any system defaults first so they can be overridden later
[ -r /etc/profile ] && source /etc/profile
-# rwx user only
-umask 0077
-
-# Environment variables that may be overidden in .bash_profile_local
-export PAGER="less"
-export EDITOR="vim"
-export CVS_RSH="ssh"
-export RSYNC_RSH="ssh"
-export PYTHONSTARTUP="$HOME/.pythonrc.py"
-export HISTCONTROL="ignoredups"
-export HISTSIZE="10000"
-
-# Local customisations
-[ -f ~/.bash_profile_local ] && source ~/.bash_profile_local
-
-# Never want to override this, and we want ~/bin at the front of PATH
-export PATH="$(echo "$PATH" | sed -e 's/:.:/:/g')"
-export PATH="$HOME/bin:$PATH"
-
-# Interactive mode stuff
-[ -r ~/.bashrc ] && source ~/.bashrc
+# We run the environment settings for all shells to ensure it's always set up
+source "${HOME}/.bash/environment"
+# An interactive shell starting bash_profile must be a login shell (man bash)
+# We run the login script and the interactive setup
+if [ -n "${PS1}" ]; then
+ source "${HOME}/.bash/login"
+ source "${HOME}/.bash/interactive"
+fi
-# Run when a random bash is started. This is always run after the login
-# shell. It sets up the shell to have a nice prompt and xterm titlebar, etc.
-# It should NOT set any environment variables like the PATH.
-# Copy this around to all your machines and make machine specific
-# customisations to ~/.bashrc_local
+# We run the environment settings for all shells to ensure it's always set up
+source "${HOME}/.bash/environment"
-# Run .bash_profile if logging in from ssh
-[ ${RUN_BASH_PROFILE:-0} -eq 1 -a -f ~/.bash_profile ] && source ~/.bash_profile && return
-
-# If not running interactively do nothing
-[ -z "$PS1" ] && return
-
-# Terminals that we want coloured prompts in
-[ -n "$COLORTERM" ] && PS1_COLOR=1
-[ "$TERM" = "linux" ] && PS1_COLOR=1 && DARK=1
-[ "$TERM" = "screen" ] && PS1_COLOR=1
-[ "$TERM" = "xterm" ] && PS1_COLOR=1
-[ "$TERM" = "xterm-color" ] && PS1_COLOR=1
-[ "$TERM" = "rxvt" ] && PS1_COLOR=1
-[ "$TERM" = "rxvt-unicode" ] && PS1_COLOR=1
-
-# Use colours appropriate to a light on dark terminal, we can autodetect
-# this for some terminals, for others we define it above.
-if [ -n "$COLORFGBG" ]; then
- FGCOLOR=$(echo $COLORFGBG | cut -d ';' -f 1)
- BGCOLOR=$(echo $COLORFGBG | cut -d ';' -f 3)
- if [ "$FGCOLOR" -gt "$BGCOLOR" ]; then
- DARK=1
- fi
- unset FGCOLOR
- unset BGCOLOR
-elif [ ${DARK:-0} -eq 0 ]; then
- export COLORFGBG="0;default;15"
-elif [ ${DARK:-0} -eq 1 ]; then
- export COLORFGBG="15;default;0"
-fi
-
-# Set the prompt colour, and the colors for the 'ls' command appropriately,
-# depending on the background of the terminal.
-if [ ${PS1_COLOR:-0} -eq 1 ]; then
- if [ ${DARK:-0} -eq 0 ]; then
- LS_COLORS="no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35"
- PS1='\[\033[31m\]\u@\h\[\033[00m\]:\[\033[34m\]\w\[\033[00m\]\$ '
- else
- LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:'
- PS1='\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
- fi
-
- export LS_COLORS
- unset PS1_COLOR
- unset DARK
-else
- PS1='\u@\h:\w\$ '
+# An interactive shell starting bashrc is not a login shell, just run
+# interactive setup
+if [ -n "${PS1}" ]; then
+ source "${HOME}/.bash/interactive"
fi
-
-function DARKTERM {
- unset COLORFGBG
- DARK=1 && source ~/.bashrc
-}
-
-# xterm titlebar displays current command
-case "$TERM" in
-xterm*|rxvt*)
- HOSTNAME="$(hostname | cut -d '.' -f 1)"
- CWD_WITHHOME='"$(echo "$PWD" | sed "s|^$HOME|~|")"'
- PROMPT_COMMAND="echo -ne \"\033]0;${HOSTNAME}: ${CWD_WITHHOME}\007\""
- ;;
-*)
- ;;
-esac
-
-# Useful aliases
-alias ls='ls --color=auto'
-alias ll='ls -hlF'
-alias la='ls -ha'
-alias l='ls -halF'
-alias rm='rm -i'
-alias less='less -R'
-alias screen='TERM=xterm screen'
-
-shopt -s checkwinsize
-
-# Local customisations
-[ -r ~/.bashrc_local ] && source ~/.bashrc_local
-