dot/shell-rc, etc.: Introduce an easily user-definable prompt section.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 12 Feb 2022 15:24:40 +0000 (15:24 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 12 Feb 2022 15:26:33 +0000 (15:26 +0000)
dot/bashrc
dot/shell-rc
dot/zshrc

index f655756..9175064 100644 (file)
@@ -62,6 +62,7 @@ __mdw_set_prompt_hacks () {
        *) bold="\[$(tput bold)\]" unbold="\[$(tput sgr0)\]" ;;
       esac
       gitcolour="\[$(tput setaf 6)\]"
+      extracolour="\[$(tput setaf 3)\]"
       rccolour="\[$(tput setaf 1)\]"
       uncolour="\[$(tput op)\]"
       nl="\[\r\]"
index c62471e..b65f63e 100644 (file)
@@ -93,9 +93,9 @@ __mdw_set_prompt_pieces () {
 
   ## Fancy highlighting in some terminals.
   local bold unbold nl more host dir
-  local gitcolour rccolour uncolour
+  local gitcolour extracolour rccolour uncolour
   bold="" unbold="" nl="" more=""
-  gitcolour="" rccolour="" uncolour=""
+  gitcolour="" extracolour="" rccolour="" uncolour=""
   __mdw_set_prompt_hacks
 
   ## Choose the right delimiters.  Highlight root prompts specially;
@@ -138,6 +138,8 @@ __mdw_set_prompt_pieces () {
   __mdw_prompt_git_right="$uncolour$bold"
   __mdw_prompt_rc_left="$unbold$rccolour"
   __mdw_prompt_rc_right="$uncolour$bold"
+  __mdw_prompt_extra_left="$unbold$extracolour"
+  __mdw_prompt_extra_right="$uncolour$bold"
   __mdw_prompt_right="$right$unbold"
   __mdw_prompt_more=" $more$bold>$unbold "
 }
@@ -150,7 +152,7 @@ __mdw_set_prompt () {
       ;;
     *)
       __mdw_last_rc=$?
-      local git rc
+      local git extra rc
       if type __git_ps1 >/dev/null 2>&1; then
        git="$__mdw_prompt_git_left$(__git_ps1)$__mdw_prompt_git_right"
       else
@@ -160,7 +162,11 @@ __mdw_set_prompt () {
        0) rc="" ;;
        *) rc="$__mdw_prompt_rc_left rc=$__mdw_last_rc$__mdw_prompt_rc_right" ;;
       esac
-      PS1="$__mdw_prompt_left$git$rc$__mdw_prompt_right"
+      case $__mdw_prompt_extra in
+       ?*) extra="$__mdw_prompt_extra_left [$__mdw_prompt_extra]$__mdw_prompt_extra_right" ;;
+       *) extra="" ;;
+      esac
+      PS1="$__mdw_prompt_left$git$extra$rc$__mdw_prompt_right"
       PS2="$PS1$__mdw_prompt_more"
       unset __mdw_last_rc
       ;;
index d56fde2..3466d6c 100644 (file)
--- a/dot/zshrc
+++ b/dot/zshrc
@@ -48,7 +48,7 @@ __mdw_set_prompt_hacks () {
   case $TERM in
     linux*|screen*|xterm*|putty*|vt100*|eterm*)
       bold=%B unbold=%b
-      gitcolour=%F{cyan} rccolour=%F{red} uncolour=%f
+      gitcolour=%F{cyan} extracolour=%F{yellow} rccolour=%F{red} uncolour=%f
       ;;
   esac
   host=%m dir=" %(6~!%-1~/.../%4~!%~)"