dot/shell-rc, etc.: Introduce an easily user-definable prompt section.
[profile] / dot / bashrc
CommitLineData
ca7933c9 1### -*-bash-*-
59c9c0e4 2###
74a53e28
MW
3### Bash session things.
4
5__mdw_shell=bash
f617db13 6
59c9c0e4
MW
7## Only do this if we haven't done it before. (Note that this guard isn't
8## exported, so subshells will need to make their own arrangements.)
e849519a 9case ${__mdw_bashrc+t} in
74a53e28 10 t) ;;
e849519a 11 *) __mdw_bashrc=t
74a53e28 12
3b41df91 13###--------------------------------------------------------------------------
4877b8d8
MW
14### Hook implementation.
15
16__mdw_precmd_hook= __mdw_preexec_hook=
17__mdw_running=t
18
19__mdw_run_precmd_hook () {
4877b8d8 20 __mdw_runhook __mdw_precmd_hook "$@"
885b29ac 21 __mdw_running=nil
4877b8d8
MW
22}
23__mdw_run_preexec_hook () {
24 case $__mdw_running in
25 t) ;;
26 nil)
27 __mdw_running=t;
28 set -- $(history 1); shift
29 __mdw_runhook __mdw_preexec_hook "$*"
30 ;;
31 esac
32}
33
34PROMPT_COMMAND=__mdw_run_precmd_hook
35trap __mdw_run_preexec_hook DEBUG
36
37###--------------------------------------------------------------------------
3b41df91
MW
38### Common shell configuration.
39
74a53e28 40. "$HOME/.shell-rc"
f617db13 41
3b41df91
MW
42###--------------------------------------------------------------------------
43### Other preliminaries.
44
59c9c0e4
MW
45## If we've not run the main profile yet, we should do that first. It sets
46## up things we rely on. Also, if there's a system script, we should run
47## that too.
74a53e28
MW
48case ${__mdw_profile+t} in t) ;; *) . "$HOME/.profile" ;; esac
49__mdw_source_if_exists /etc/bashrc
f617db13 50
5e662c38 51## Completion.
74a53e28 52__mdw_source_if_exists /etc/bash_completion "$HOME/.bash_completion"
5e662c38 53
59c9c0e4
MW
54###--------------------------------------------------------------------------
55### Prompt hacking.
f617db13 56
74a53e28 57__mdw_set_prompt_hacks () {
15b95c26 58 case "$TERM" in
8a075bd7 59 linux*|screen*|xterm*|putty*|vt100*|eterm*)
59c3438f
MW
60 case "$(tput bold)" in
61 "") bold="\[$(tput md)\]" unbold="\[$(tput me)\]" ;;
62 *) bold="\[$(tput bold)\]" unbold="\[$(tput sgr0)\]" ;;
63 esac
1273afa0 64 gitcolour="\[$(tput setaf 6)\]"
0c7867d9 65 extracolour="\[$(tput setaf 3)\]"
f00ae4fa
MW
66 rccolour="\[$(tput setaf 1)\]"
67 uncolour="\[$(tput op)\]"
9bd5ab69 68 nl="\[\r\]"
59c3438f 69 ;;
15b95c26 70 esac
74a53e28
MW
71 host='\h' dir=' \w'
72}
15b95c26 73
74a53e28
MW
74## Only bother if the shell is interactive.
75if [ -t 0 ]; then
76 PROMPT_DIRTRIM=5
77 __mdw_source_if_exists /usr/lib/git-core/git-sh-prompt
78 __mdw_set_prompt_pieces
59c9c0e4 79fi
15b95c26 80
59c9c0e4
MW
81###--------------------------------------------------------------------------
82### Other shell tweaking.
f617db13 83
59c9c0e4 84## Random shell tweaks.
f617db13
MW
85notify=1
86set -b
87shopt -u cdable_vars
88shopt -s cdspell
89shopt -s checkhash
90shopt -s checkwinsize
91shopt -s cmdhist
92shopt -u dotglob
93shopt -s expand_aliases
94shopt -s extglob
08404785 95if (( ${BASH_VERSINFO[0]} >= 4 )); then shopt -s globstar; fi
83a3b1eb 96shopt -s gnu_errfmt
f617db13 97shopt -s histappend
92e4caa8 98set -o histexpand
f617db13
MW
99shopt -s histreedit
100shopt -u histverify
101shopt -s hostcomplete
102shopt -s huponexit
103shopt -s interactive_comments
104shopt -s lithist
105shopt -u mailwarn
106shopt -u nocaseglob
107shopt -u nullglob
108shopt -s promptvars
109shopt -u shift_verbose
110shopt -s sourcepath
83a3b1eb
MW
111HISTCONTROL=ignorespace:erasedups
112
59c9c0e4
MW
113###--------------------------------------------------------------------------
114### Finishing touches.
f617db13 115
59c9c0e4 116## Run any local hooks.
74a53e28 117__mdw_source_if_exists "$HOME/.bashrc-local"
59c9c0e4
MW
118
119###----- That's all, folks --------------------------------------------------
0d9bb87e 120
74a53e28 121esac