bin/x2x-privsep: Add (souped-up) version of this handy script.
[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)\]"
f00ae4fa
MW
65 rccolour="\[$(tput setaf 1)\]"
66 uncolour="\[$(tput op)\]"
9bd5ab69 67 nl="\[\r\]"
59c3438f 68 ;;
15b95c26 69 esac
74a53e28
MW
70 host='\h' dir=' \w'
71}
15b95c26 72
74a53e28
MW
73## Only bother if the shell is interactive.
74if [ -t 0 ]; then
75 PROMPT_DIRTRIM=5
76 __mdw_source_if_exists /usr/lib/git-core/git-sh-prompt
77 __mdw_set_prompt_pieces
59c9c0e4 78fi
15b95c26 79
59c9c0e4
MW
80###--------------------------------------------------------------------------
81### Other shell tweaking.
f617db13 82
59c9c0e4 83## Random shell tweaks.
f617db13
MW
84notify=1
85set -b
86shopt -u cdable_vars
87shopt -s cdspell
88shopt -s checkhash
89shopt -s checkwinsize
90shopt -s cmdhist
91shopt -u dotglob
92shopt -s expand_aliases
93shopt -s extglob
08404785 94if (( ${BASH_VERSINFO[0]} >= 4 )); then shopt -s globstar; fi
83a3b1eb 95shopt -s gnu_errfmt
f617db13 96shopt -s histappend
92e4caa8 97set -o histexpand
f617db13
MW
98shopt -s histreedit
99shopt -u histverify
100shopt -s hostcomplete
101shopt -s huponexit
102shopt -s interactive_comments
103shopt -s lithist
104shopt -u mailwarn
105shopt -u nocaseglob
106shopt -u nullglob
107shopt -s promptvars
108shopt -u shift_verbose
109shopt -s sourcepath
83a3b1eb
MW
110HISTCONTROL=ignorespace:erasedups
111
59c9c0e4
MW
112###--------------------------------------------------------------------------
113### Finishing touches.
f617db13 114
59c9c0e4 115## Run any local hooks.
74a53e28 116__mdw_source_if_exists "$HOME/.bashrc-local"
59c9c0e4
MW
117
118###----- That's all, folks --------------------------------------------------
0d9bb87e 119
74a53e28 120esac