chiark / gitweb /
dot/shell-rc, dot/bashrc, dot/zshrc: Introduce a formal notion of hooks.
[profile] / dot / bashrc
index 9e872f58e0246a01ae40873949152e95ff4b8c61..18a2d7df897d113c8302fe0638e51d3db6de6fbe 100644 (file)
@@ -10,6 +10,30 @@ case ${__mdw_bashrc+t} in
   t) ;;
   *) __mdw_bashrc=t
 
+###--------------------------------------------------------------------------
+### Hook implementation.
+
+__mdw_precmd_hook= __mdw_preexec_hook=
+__mdw_running=t
+
+__mdw_run_precmd_hook () {
+  __mdw_running=nil
+  __mdw_runhook __mdw_precmd_hook "$@"
+}
+__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.
 
@@ -46,18 +70,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
 
 ###--------------------------------------------------------------------------