dot/shell-rc, etc.: Introduce an easily user-definable prompt section.
[profile] / dot / bashrc
index 28d9bf9..9175064 100644 (file)
@@ -6,13 +6,42 @@ __mdw_shell=bash
 
 ## Only do this if we haven't done it before.  (Note that this guard isn't
 ## exported, so subshells will need to make their own arrangements.)
-case ${__mdw_shellrc+t} in
+case ${__mdw_bashrc+t} in
   t) ;;
-  *) __mdw_shellrc=done
+  *) __mdw_bashrc=t
+
+###--------------------------------------------------------------------------
+### Hook implementation.
+
+__mdw_precmd_hook= __mdw_preexec_hook=
+__mdw_running=t
+
+__mdw_run_precmd_hook () {
+  __mdw_runhook __mdw_precmd_hook "$@"
+  __mdw_running=nil
+}
+__mdw_run_preexec_hook () {
+  case $__mdw_running in
+    t) ;;
+    nil)
+      __mdw_running=t;
+      set -- $(history 1); shift
+      __mdw_runhook __mdw_preexec_hook "$*"
+      ;;
+  esac
+}
+
+PROMPT_COMMAND=__mdw_run_precmd_hook
+trap __mdw_run_preexec_hook DEBUG
+
+###--------------------------------------------------------------------------
+### Common shell configuration.
 
-## Fetch the common configuration.
 . "$HOME/.shell-rc"
 
+###--------------------------------------------------------------------------
+### Other preliminaries.
+
 ## If we've not run the main profile yet, we should do that first.  It sets
 ## up things we rely on.  Also, if there's a system script, we should run
 ## that too.
@@ -27,12 +56,13 @@ __mdw_source_if_exists /etc/bash_completion "$HOME/.bash_completion"
 
 __mdw_set_prompt_hacks () {
   case "$TERM" in
-    linux*|screen*|xterm*|vt100*|eterm*)
+    linux*|screen*|xterm*|putty*|vt100*|eterm*)
       case "$(tput bold)" in
        "") bold="\[$(tput md)\]" unbold="\[$(tput me)\]" ;;
        *) bold="\[$(tput bold)\]" unbold="\[$(tput sgr0)\]" ;;
       esac
       gitcolour="\[$(tput setaf 6)\]"
+      extracolour="\[$(tput setaf 3)\]"
       rccolour="\[$(tput setaf 1)\]"
       uncolour="\[$(tput op)\]"
       nl="\[\r\]"
@@ -41,18 +71,11 @@ __mdw_set_prompt_hacks () {
   host='\h' dir=' \w'
 }
 
-__mdw_before_cmd_hack () {
-  set -- $(history 1); shift
-  __mdw_preexec "$*"
-}
-
 ## Only bother if the shell is interactive.
 if [ -t 0 ]; then
   PROMPT_DIRTRIM=5
   __mdw_source_if_exists /usr/lib/git-core/git-sh-prompt
   __mdw_set_prompt_pieces
-  PROMPT_COMMAND=__mdw_precmd
-  PS0="\$(__mdw_before_cmd_hack)"
 fi
 
 ###--------------------------------------------------------------------------
@@ -72,6 +95,7 @@ shopt -s extglob
 if (( ${BASH_VERSINFO[0]} >= 4 )); then shopt -s globstar; fi
 shopt -s gnu_errfmt
 shopt -s histappend
+set -o histexpand
 shopt -s histreedit
 shopt -u histverify
 shopt -s hostcomplete