| 1 | ### -*-bash-*- |
| 2 | ### |
| 3 | ### Bash session things. |
| 4 | |
| 5 | __mdw_shell=bash |
| 6 | |
| 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.) |
| 9 | case ${__mdw_bashrc+t} in |
| 10 | t) ;; |
| 11 | *) __mdw_bashrc=t |
| 12 | |
| 13 | ###-------------------------------------------------------------------------- |
| 14 | ### Hook implementation. |
| 15 | |
| 16 | __mdw_precmd_hook= __mdw_preexec_hook= |
| 17 | __mdw_running=t |
| 18 | |
| 19 | __mdw_run_precmd_hook () { |
| 20 | __mdw_runhook __mdw_precmd_hook "$@" |
| 21 | __mdw_running=nil |
| 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 | |
| 34 | PROMPT_COMMAND=__mdw_run_precmd_hook |
| 35 | trap __mdw_run_preexec_hook DEBUG |
| 36 | |
| 37 | ###-------------------------------------------------------------------------- |
| 38 | ### Common shell configuration. |
| 39 | |
| 40 | . "$HOME/.shell-rc" |
| 41 | |
| 42 | ###-------------------------------------------------------------------------- |
| 43 | ### Other preliminaries. |
| 44 | |
| 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. |
| 48 | case ${__mdw_profile+t} in t) ;; *) . "$HOME/.profile" ;; esac |
| 49 | __mdw_source_if_exists /etc/bashrc |
| 50 | |
| 51 | ## Completion. |
| 52 | __mdw_source_if_exists /etc/bash_completion "$HOME/.bash_completion" |
| 53 | |
| 54 | ###-------------------------------------------------------------------------- |
| 55 | ### Prompt hacking. |
| 56 | |
| 57 | __mdw_set_prompt_hacks () { |
| 58 | case "$TERM" in |
| 59 | linux*|screen*|xterm*|putty*|vt100*|eterm*) |
| 60 | case "$(tput bold)" in |
| 61 | "") bold="\[$(tput md)\]" unbold="\[$(tput me)\]" ;; |
| 62 | *) bold="\[$(tput bold)\]" unbold="\[$(tput sgr0)\]" ;; |
| 63 | esac |
| 64 | gitcolour="\[$(tput setaf 6)\]" |
| 65 | extracolour="\[$(tput setaf 3)\]" |
| 66 | rccolour="\[$(tput setaf 1)\]" |
| 67 | uncolour="\[$(tput op)\]" |
| 68 | nl="\[\r\]" |
| 69 | ;; |
| 70 | esac |
| 71 | host='\h' dir=' \w' |
| 72 | } |
| 73 | |
| 74 | ## Only bother if the shell is interactive. |
| 75 | if [ -t 0 ]; then |
| 76 | PROMPT_DIRTRIM=5 |
| 77 | __mdw_source_if_exists /usr/lib/git-core/git-sh-prompt |
| 78 | __mdw_set_prompt_pieces |
| 79 | fi |
| 80 | |
| 81 | ###-------------------------------------------------------------------------- |
| 82 | ### Other shell tweaking. |
| 83 | |
| 84 | ## Random shell tweaks. |
| 85 | notify=1 |
| 86 | set -b |
| 87 | shopt -u cdable_vars |
| 88 | shopt -s cdspell |
| 89 | shopt -s checkhash |
| 90 | shopt -s checkwinsize |
| 91 | shopt -s cmdhist |
| 92 | shopt -u dotglob |
| 93 | shopt -s expand_aliases |
| 94 | shopt -s extglob |
| 95 | if (( ${BASH_VERSINFO[0]} >= 4 )); then shopt -s globstar; fi |
| 96 | shopt -s gnu_errfmt |
| 97 | shopt -s histappend |
| 98 | set -o histexpand |
| 99 | shopt -s histreedit |
| 100 | shopt -u histverify |
| 101 | shopt -s hostcomplete |
| 102 | shopt -s huponexit |
| 103 | shopt -s interactive_comments |
| 104 | shopt -s lithist |
| 105 | shopt -u mailwarn |
| 106 | shopt -u nocaseglob |
| 107 | shopt -u nullglob |
| 108 | shopt -s promptvars |
| 109 | shopt -u shift_verbose |
| 110 | shopt -s sourcepath |
| 111 | HISTCONTROL=ignorespace:erasedups |
| 112 | |
| 113 | ###-------------------------------------------------------------------------- |
| 114 | ### Finishing touches. |
| 115 | |
| 116 | ## Run any local hooks. |
| 117 | __mdw_source_if_exists "$HOME/.bashrc-local" |
| 118 | |
| 119 | ###----- That's all, folks -------------------------------------------------- |
| 120 | |
| 121 | esac |