Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: update prompt themes



This is an update for the prompt theme system addressing numerous things,
not just fixing the colours.  I've tried every theme out, but the
effects are fiddly so people may still notice problems.

- Use %F, %K wherever possible.  "grey" had to become "black".
- Hence remove the PSZZZ... hack for sanitizing variable lists.
- No remaining dependence on "colors", so no longer loaded.
- Overhaul of use of precmd and preexec.  Use the hook functions
  designed for exactly this purpose so as not to trash any existing
  use of the functions.  No way of doing this with traps, unfortunately,
  but the only example is Bart's SIGWINCH handler which is intelligently
  handled already.
- Updated add-zsh-hook to be able to remove patterns from the hooks.
- Improved use of special characters.  Used a hash to make localizing
  easier.  Added some missing codes used by one of the prompts (elite: I'm
  not convinced by the results, but that's what iconv gave for
  converting from IBM852 to UTF-8, which is the character set the
  function mentions).
- Fix the assignment in the non-UTF-8 branch of prompt_special_chars,
  which can't have worked for donkey's years (or is that donkeys' years?
  wouldn't it be "a donkey's years" or "Donkey's years" otherwise?)
- Replace all obvious uses of leaving colour sequences activated after
  the prompt by the zle_highlight default attribute (already done by
  Oliver in his prompt).  This also replaces use of POSTEDIT and preexec
  to return the colours to normal.  POSTEDIT shouldn't usually be
  needed now.
- Replace use of precmd to fix up options by use of the prompt_opts
  array (already there but inconsistently used).
- Finally added my own somewhat minimal prompt.

Phrases along the lines of "why did I bother" have been drifting across
my mind.

If anyone wants to write a prompt generator for zsh/newuser, feel free.
I don't.

Index: Functions/Misc/add-zsh-hook
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Misc/add-zsh-hook,v
retrieving revision 1.2
diff -u -r1.2 add-zsh-hook
--- Functions/Misc/add-zsh-hook	19 Apr 2007 19:54:01 -0000	1.2
+++ Functions/Misc/add-zsh-hook	17 May 2008 22:36:10 -0000
@@ -4,6 +4,9 @@
 #
 # With -d, remove the function from the hook instead; delete the hook
 # variable if it is empty.
+# 
+# -D behaves like -d, but pattern characters are active in the
+# function name, so any matching function will be deleted from the hook.
 #
 # Without -d, the FUNCTION is marked for autoload; -U is passed down to
 # autoload if that is given.  (This is harmless if the function is actually
@@ -18,12 +21,16 @@
 local -a autoopts
 integer del
 
-while getopts "d" opt; do
+while getopts "dDU" opt; do
   case $opt in
     (d)
     del=1
     ;;
 
+    (D)
+    del=2
+    ;;
+
     (U)
     autoopts+=(-$opt)
     ;;
@@ -46,7 +53,11 @@
 if (( del )); then
   # delete, if hook is set
   if (( ${(P)+hook} )); then
-    set -A $hook ${(P)hook:#$fn}
+    if (( del == 2 )); then
+      set -A $hook ${(P)hook:#${~fn}}
+    else
+      set -A $hook ${(P)hook:#$fn}
+    fi
     # unset if no remaining entries --- this can give better
     # performance in some cases
     (( ${(P)#hook} )) || unset $hook
Index: Functions/Prompts/prompt_adam1_setup
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Prompts/prompt_adam1_setup,v
retrieving revision 1.2
diff -u -r1.2 prompt_adam1_setup
--- Functions/Prompts/prompt_adam1_setup	3 Jul 2007 17:06:06 -0000	1.2
+++ Functions/Prompts/prompt_adam1_setup	17 May 2008 22:36:10 -0000
@@ -24,14 +24,13 @@
   prompt_adam1_color2=${2:-'cyan'}
   prompt_adam1_color3=${3:-'green'}
 
-  base_prompt="%{$bg_no_bold[$prompt_adam1_color1]%}%n@%m%{$reset_color%} "
-  post_prompt="%{$reset_color%}"
+  base_prompt="%K{$prompt_adam1_color1}%n@%m%k "
+  post_prompt="%b%f%k"
 
-  base_prompt_no_color=$(echo "$base_prompt" | perl -pe "s/%{.*?%}//g")
-  post_prompt_no_color=$(echo "$post_prompt" | perl -pe "s/%{.*?%}//g")
+  base_prompt_no_color=$(echo "$base_prompt" | perl -pe "s/%(K{.*?}|k)//g")
+  post_prompt_no_color=$(echo "$post_prompt" | perl -pe "s/%(K{.*?}|k)//g")
 
-  precmd  () { prompt_adam1_precmd }
-  preexec () { }
+  add-zsh-hook precmd prompt_adam1_precmd
 }
 
 prompt_adam1_precmd () {
@@ -43,10 +42,10 @@
   base_prompt_etc=$(print -P "$base_prompt%(4~|...|)%3~")
   prompt_length=${#base_prompt_etc}
   if [[ $prompt_length -lt 40 ]]; then
-    path_prompt="%{$fg_bold[$prompt_adam1_color2]%}%(4~|...|)%3~%{$fg_bold[white]%}"
+    path_prompt="%B%F{$prompt_adam1_color2}%(4~|...|)%3~%F{white}"
   else
     space_left=$(( $COLUMNS - $#base_prompt_expanded_no_color - 2 ))
-    path_prompt="%{$fg_bold[$prompt_adam1_color3]%}%${space_left}<...<%~$prompt_newline%{$fg_bold_white%}"
+    path_prompt="%B%F{$prompt_adam1_color3}%${space_left}<...<%~$prompt_newline%F{white}"
   fi
   PS1="$base_prompt$path_prompt %# $post_prompt"
   PS2="$base_prompt$path_prompt %_> $post_prompt"
Index: Functions/Prompts/prompt_adam2_setup
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Prompts/prompt_adam2_setup,v
retrieving revision 1.5
diff -u -r1.5 prompt_adam2_setup
--- Functions/Prompts/prompt_adam2_setup	14 Jun 2007 16:10:52 -0000	1.5
+++ Functions/Prompts/prompt_adam2_setup	17 May 2008 22:36:10 -0000
@@ -49,42 +49,44 @@
   prompt_adam2_color4=${4:-'white'}   # user input
 
   local prompt_gfx_bbox 
-  prompt_gfx_tbox="%{$fg_bold[$prompt_adam2_color1]%}${prompt_gfx_tlc}%{$fg_no_bold[$prompt_adam2_color1]%}${prompt_gfx_hyphen}"
-  prompt_gfx_bbox="%{$fg_bold[$prompt_adam2_color1]%}${prompt_gfx_blc}${prompt_gfx_hyphen}%{$fg_no_bold[$prompt_adam2_color1]%}"
+  prompt_gfx_tbox="%B%F{$prompt_adam2_color1}${prompt_gfx_tlc}%b%F{$prompt_adam2_color1}${prompt_gfx_hyphen}"
+  prompt_gfx_bbox="%B%F{$prompt_adam2_color1}${prompt_gfx_blc}${prompt_gfx_hyphen}%b%F{$prompt_adam2_color1}"
 
   # This is a cute hack.  Well I like it, anyway.
-  prompt_gfx_bbox_to_mbox=$'%{\e[A\r'"$fg_bold[$prompt_adam2_color1]${prompt_gfx_mlc}$fg_no_bold[$prompt_adam2_color1]${prompt_gfx_hyphen}"$'\e[B%}'
+  prompt_gfx_bbox_to_mbox=$'%{\e[A\r'"%}%B%F{$prompt_adam2_color1}${prompt_gfx_mlc}%b%F{$prompt_adam2_color1}${prompt_gfx_hyphen}%{"$'\e[B%}'
 
-  prompt_l_paren="%{$fg_bold[grey]%}("
-  prompt_r_paren="%{$fg_bold[grey]%})"
+  prompt_l_paren="%B%F{black}("
+  prompt_r_paren="%B%F{black})"
 
-  prompt_user_host="%{$fg_no_bold[$prompt_adam2_color3]%}%n%{$fg_bold[$prompt_adam2_color3]%}@%{$fg_no_bold[$prompt_adam2_color3]%}%m"
+  prompt_user_host="%b%F{$prompt_adam2_color3}%n%B%F{$prompt_adam2_color3}@%b%F{$prompt_adam2_color3}%m"
 
-  prompt_line_1a="$prompt_gfx_tbox$prompt_l_paren%{$fg_bold[$prompt_adam2_color2]%}%~$prompt_r_paren%{$fg_no_bold[$prompt_adam2_color1]%}"
-  prompt_line_1b="$prompt_l_paren$prompt_user_host$prompt_r_paren%{$fg_no_bold[$prompt_adam2_color1]%}${prompt_gfx_hyphen}"
+  prompt_line_1a="$prompt_gfx_tbox$prompt_l_paren%B%F{$prompt_adam2_color2}%~$prompt_r_paren%b%F{$prompt_adam2_color1}"
+  prompt_line_1b="$prompt_l_paren$prompt_user_host$prompt_r_paren%b%F{$prompt_adam2_color1}${prompt_gfx_hyphen}"
 
-  prompt_line_2="$prompt_gfx_bbox${prompt_gfx_hyphen}%{$fg_bold[white]%}"
+  prompt_line_2="$prompt_gfx_bbox${prompt_gfx_hyphen}%B%F{white}"
 
   prompt_char="%(!.#.>)"
 
-  precmd () { prompt_adam2_precmd; setopt promptsubst }
-  preexec () { prompt_adam2_preexec }
+  prompt_opts=(cr subst percent)
+
+  add-zsh-hook precmd prompt_adam2_precmd
 }
 
-prompt_adam2_precmd () {
+prompt_adam2_precmd() {
   setopt noxtrace localoptions extendedglob
   local prompt_line_1
 
   prompt_adam2_choose_prompt
 
-  PS1="$prompt_line_1$prompt_newline$prompt_line_2%{$fg_bold[white]%}$prompt_char %{$fg_bold[$prompt_adam2_color4]%}"
-  PS2="$prompt_line_2%{$prompt_gfx_bbox_to_mbox$fg_bold[white]%}%_> %{$fg_bold[$prompt_adam2_color4]%}"
-  PS3="$prompt_line_2%{$prompt_gfx_bbox_to_mbox$fg_bold[white]%}?# %{$fg_bold[$prompt_adam2_color4]%}"
+  PS1="$prompt_line_1$prompt_newline$prompt_line_2%B%F{white}$prompt_char %b%f%k"
+  PS2="$prompt_line_2$prompt_gfx_bbox_to_mbox%B%F{white}%_> %b%f%k"
+  PS3="$prompt_line_2$prompt_gfx_bbox_to_mbox%B%F{white}?# %b%f%k"
+  zle_highlight[(r)default:*]="default:fg=$prompt_adam2_color4,bold"
 }
 
 prompt_adam2_choose_prompt () {
-  local prompt_line_1a_width=${#${(S%%)prompt_line_1a//\%\{*\%\}}}
-  local prompt_line_1b_width=${#${(S%%)prompt_line_1b//\%\{*\%\}}}
+  local prompt_line_1a_width=${#${(S%%)prompt_line_1a//(\%([KF1]|)\{*\}|\%[Bbkf])}}
+  local prompt_line_1b_width=${#${(S%%)prompt_line_1b//(\%([KF1]|)\{*\}|\%[Bbkf])}}
 
   local prompt_padding_size=$(( COLUMNS
                                   - prompt_line_1a_width
@@ -110,11 +112,7 @@
 
   # Still didn't fit; truncate 
   local prompt_pwd_size=$(( COLUMNS - 5 ))
-  prompt_line_1="$prompt_gfx_tbox$prompt_l_paren%{$fg_bold[$prompt_adam2_color2]%}%$prompt_pwd_size<...<%~%<<$prompt_r_paren%{$fg_no_bold[$prompt_adam2_color1]$prompt_gfx_hyphen%}"
-}
-
-prompt_adam2_preexec () {
-  print -n "$reset_color"
+  prompt_line_1="$prompt_gfx_tbox$prompt_l_paren%B%F{$prompt_adam2_color2}%$prompt_pwd_size<...<%~%<<$prompt_r_paren%b%F{$prompt_adam2_color1}$prompt_gfx_hyphen"
 }
 
 prompt_adam2_setup "$@"
Index: Functions/Prompts/prompt_bart_setup
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Prompts/prompt_bart_setup,v
retrieving revision 1.13
diff -u -r1.13 prompt_bart_setup
--- Functions/Prompts/prompt_bart_setup	14 Oct 2007 16:35:10 -0000	1.13
+++ Functions/Prompts/prompt_bart_setup	17 May 2008 22:36:10 -0000
@@ -70,7 +70,7 @@
 
 prompt_bart_precmd () {
     setopt localoptions noxtrace noksharrays unset
-    local zero='%([BSUbsu]|{*%})' escape colno lineno
+    local zero='%([BSUbfksu]|FB{*})' escape colno lineno
 
     # Using psvar here protects against unwanted promptsubst expansions.
 
@@ -102,7 +102,7 @@
     setopt localoptions noxtrace noksharrays
 
     local -ah ps1
-    local -h host hist1 hist2 dir space date time rs="%{$reset_color%}"
+    local -h host hist1 hist2 dir space date time rs="%b%f%k"
     local -h eon="%(?.[.%20(?.[%U.%S[))" eoff="%(?.].%20(?.%u].]%s))"
 
     # Set up the components of the upper line
@@ -140,17 +140,19 @@
     setopt localoptions nolocaltraps noksharrays unset
 
     # Delete ourself from TRAPWINCH if not using our precmd insert.
-    [[ $functions[precmd] = *prompt_bart_precmd* ]] && prompt_bart_ps1 ||
+    [[ $precmd_functions = *prompt_bart_precmd* ]] && prompt_bart_ps1 ||
 	functions[TRAPWINCH]="${functions[TRAPWINCH]//prompt_bart_winch}"
 }
 
 prompt_bart_setup () {
     setopt localoptions nolocaltraps noksharrays unset
+    typeset -gA fg
 
     # A few extra niceties ...
     repeat 1 case "$1:l" in
       (off|disable)
-	functions[precmd]="${functions[precmd]//prompt_bart_precmd}"
+        precmd_functions[(r)prompt_*_precmd]=
+	precmd_functions=($precmd_functions)
 	functions[TRAPWINCH]="${functions[TRAPWINCH]//prompt_bart_winch}"
 	[[ $prompt_theme[1] = bart ]] && PS1=${${(f)PS1}[-1]}
 	return 1
@@ -161,22 +163,22 @@
 	;&
       (*)
 	# Abuse the fg assoc to hold our selected colors ...
-	fg[%m]=$fg[${1:-red}]
-	fg[%h]=$fg[${2:-blue}]
-	fg[%~]=$fg[${3:-none}]
-	fg[%D]=$fg[${4:-none}]
-	fg[%@]=$fg[${1:-red}]
+	fg[%m]="%F{${1:-red}}"
+	fg[%h]="%F{${2:-blue}}"
+	fg[%~]="%F{${3:-default}}"
+	fg[%D]="%F{${4:-default}}"
+	fg[%@]="%F{${1:-red}}"
 	;;
     esac
 
     prompt_bart_ps1
 
     # No RPS1 by default because prompt_off_setup doesn't fix it.
-    (($#RPS1 && $# > 4)) && RPS1="%{$fg[$5]%}$RPS1%{$reset_color%}"
+    (($#RPS1 && $# > 4)) && RPS1="%F{$5}$RPS1%f"
 
     # Paste our special commands into precmd and TRAPWINCH
-    functions[precmd]="${functions[precmd]//prompt_*_precmd}
-	prompt_bart_precmd"
+    
+    add-zsh-hook precmd prompt_bart_precmd
     functions[TRAPWINCH]="${functions[TRAPWINCH]//prompt_bart_winch}
 	prompt_bart_winch"
 
Index: Functions/Prompts/prompt_bigfade_setup
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Prompts/prompt_bigfade_setup,v
retrieving revision 1.3
diff -u -r1.3 prompt_bigfade_setup
--- Functions/Prompts/prompt_bigfade_setup	14 Jun 2007 16:10:52 -0000	1.3
+++ Functions/Prompts/prompt_bigfade_setup	17 May 2008 22:36:10 -0000
@@ -27,15 +27,14 @@
   local date=${3:-'white'}
   local cwd=${4:-'yellow'}
 
-  local char_333 char_262 char_261 char_260
+  local -A schars
   autoload -U prompt_special_chars
   prompt_special_chars
 
-  PS1="%{$bold_color$fg[$fadebar]$bold_color%}$char_333$char_262$char_261$char_260%{$bold_color$fg[$userhost]$bg[$fadebar]%}%n@%m%{$reset_color$fg[$fadebar]$bg[grey]%}$char_260$char_261$char_262$char_333%{$reset_color$fg[$fadebar]$bg[grey]%}$char_333$char_262$char_261$char_260%{$bold_color$fg[$date]$bg[grey]%} %D{%a %b %d} %D{%I:%M:%S%P}$prompt_newline%{$bold_color$fg[$cwd]$bg[grey]%}$PWD>%{$reset_color%} "
-  PS2="%{$bold_color$fg[$fadebar]$bold_color%}$char_333$char_262$char_261$char_260%{$reset_color$fg[$fadebar]$bg[grey]%}$char_260$char_261$char_262$char_333%{$reset_color$fg[$fadebar]$bg[grey]%}$char_333$char_262$char_261$char_260%{$bold_color$bold_color$fg[$fadebar]%}>%{$reset_color%} "
+  PS1="%B%F{$fadebar}$schars[333]$schars[262]$schars[261]$schars[260]%B%F{$userhost}%K{$fadebar}%n@%m%b%k%f%F{$fadebar}%K{black}$schars[260]$schars[261]$schars[262]$schars[333]%b%f%k%F{$fadebar}%K{black}$schars[333]$schars[262]$schars[261]$schars[260]%B%F{$date}%K{black} %D{%a %b %d} %D{%I:%M:%S%P}$prompt_newline%B%F{$cwd}%K{black}$PWD>%b%f%k "
+  PS2="%B%F{$fadebar}$schars[333]$schars[262]$schars[261]$schars[260]%b%F{$fadebar}%K{black}$schars[260]$schars[261]$schars[262]$schars[333]%F{$fadebar}%K{black}$schars[333]$schars[262]$schars[261]$schars[260]%B%F{$fadebar}>%b%f%k "
 
-  precmd () { setopt promptsubst }
-  preexec () { }
+  prompt_opts=(cr subst percent)
 }
 
 prompt_bigfade_preview () {
Index: Functions/Prompts/prompt_clint_setup
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Prompts/prompt_clint_setup,v
retrieving revision 1.8
diff -u -r1.8 prompt_clint_setup
--- Functions/Prompts/prompt_clint_setup	22 Nov 2007 19:15:17 -0000	1.8
+++ Functions/Prompts/prompt_clint_setup	17 May 2008 22:36:10 -0000
@@ -21,36 +21,35 @@
   pcc[4]=${4:-'yellow'}
   pcc[5]=${5:-'white'}
 
-  pc['\[']="%{$fg_no_bold[$pcc[1]]%}["
-  pc['\]']="%{$fg_no_bold[$pcc[1]]%}]"
-  pc['<']="%{$fg_no_bold[$pcc[1]]%}<"
-  pc['>']="%{$fg_no_bold[$pcc[1]]%}>"
-  pc['\(']="%{$fg_no_bold[$pcc[1]]%}("
-  pc['\)']="%{$fg_no_bold[$pcc[1]]%})"
-
-  p_date="$pc['\[']%{$fg_no_bold[$pcc[2]]%}%D{%a %y/%m/%d %R %Z}$pc['\]']"
-  p_tty="$pc['\[']%{$fg_no_bold[$pcc[3]]%}%l$pc['\]']"
-  p_plat="$pc['\[']%{$fg_no_bold[$pcc[2]]%}${MACHTYPE}/${OSTYPE}/$(uname -r)$pc['\]']"
-  p_ver="$pc['\[']%{$fg_no_bold[$pcc[2]]%}${ZSH_VERSION}$pc['\]']"
+  pc['\[']="%F{$pcc[1]}["
+  pc['\]']="%F{$pcc[1]}]"
+  pc['<']="%F{$pcc[1]}<"
+  pc['>']="%F{$pcc[1]}>"
+  pc['\(']="%F{$pcc[1]}("
+  pc['\)']="%F{$pcc[1]})"
+
+  p_date="$pc['\[']%F{$pcc[2]}%D{%a %y/%m/%d %R %Z}$pc['\]']"
+  p_tty="$pc['\[']%F{$pcc[3]}%l$pc['\]']"
+  p_plat="$pc['\[']%F{$pcc[2]}${MACHTYPE}/${OSTYPE}/$(uname -r)$pc['\]']"
+  p_ver="$pc['\[']%F{$pcc[2]}${ZSH_VERSION}$pc['\]']"
 
-  [[ -n "$WINDOW" ]] && p_win="$pc['\(']%{$fg_bold[$pcc[4]]%}$WINDOW$pc['\)']"
+  [[ -n "$WINDOW" ]] && p_win="$pc['\(']%F{$pcc[4]}$WINDOW$pc['\)']"
 
-  p_userpwd="$pc['<']%{$fg_no_bold[$pcc[3]]%}%n@%m$p_win%{$fg_bold[$pcc[5]]%}:%{$fg_no_bold[$pcc[4]]%}%~$pc['>']"
+  p_userpwd="$pc['<']%F{$pcc[3]}%n@%m$p_win%F{$pcc[5]}:%F{$pcc[4]}%~$pc['>']"
   p_git="%(2v.-%U%2v%u-.)"
 
-  p_shlvlhist="%{$reset_color%}zsh%(2L./$SHLVL.) %B%h%b "
+  p_shlvlhist="%fzsh%(2L./$SHLVL.) %B%h%b "
   p_rc="%(?..[%?%1v] )"
-  p_end="%{$reset_color%}%B%#%b %{$fg_no_bold[$pcc[2]]%}"
+  p_end="%f%B%#%b "
 
-  POSTEDIT="$reset_color"
+  zle_highlight[(r)default:*]=default:$pcc[2]
 
   prompt="$p_date$p_tty$p_plat$p_ver
 $p_userpwd
 $p_shlvlhist$p_rc$p_git$p_end"
   PS2='%(4_.\.)%3_> %E'
 
-  precmd () { prompt_clint_precmd }
-  preexec () { }
+  add-zsh-hook precmd prompt_clint_precmd
 }
 
 prompt_clint_precmd () {
@@ -67,7 +66,6 @@
   git_dir=$(git-rev-parse --git-dir 2> /dev/null) || return
   git_ref=$(git-symbolic-ref HEAD 2> /dev/null) || git_ref="(no branch)"
   psvar[2]=${git_ref#refs/heads/}
-
 }
 
 prompt_clint_setup "$@"
Index: Functions/Prompts/prompt_elite2_setup
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Prompts/prompt_elite2_setup,v
retrieving revision 1.4
diff -u -r1.4 prompt_elite2_setup
--- Functions/Prompts/prompt_elite2_setup	14 Jun 2007 16:10:52 -0000	1.4
+++ Functions/Prompts/prompt_elite2_setup	17 May 2008 22:36:10 -0000
@@ -21,24 +21,23 @@
   local text_col=${1:-'cyan'}
   local parens_col=${2:-$text_col}
 
-  local char_333 char_262 char_261 char_260
+  local -A schars
   autoload -U prompt_special_chars
   prompt_special_chars
 
-  local text="%{$fg_no_bold[$text_col]%}"
-  local parens="%{$fg_bold[$parens_col]%}"
-  local punct="%{$fg_bold[grey]%}"
-  local reset="%{$reset_color%}"
+  local text="%b%F{$text_col}"
+  local parens="%B%F{$parens_col}"
+  local punct="%B%F{black}"
+  local reset="%b%f"
 
   local lpar="$parens($text"
   local rpar="$parens)$text"
 
-  PS1="$punct$char_332$text$char_304$lpar%n$punct@$text%m$rpar$char_304$lpar%!$punct/$text%y$rpar$char_304$lpar%D{%I:%M%P}$punct:$text%D{%m/%d/%y}$rpar$char_304$punct-$reset$prompt_newline$punct$char_300$text$char_304$lpar%#$punct:$text%~$rpar$char_304$punct-$reset " 
+  PS1="$punct$schars[332]$text$schars[304]$lpar%n$punct@$text%m$rpar$schars[304]$lpar%!$punct/$text%y$rpar$schars[304]$lpar%D{%I:%M%P}$punct:$text%D{%m/%d/%y}$rpar$schars[304]$punct-$reset$prompt_newline$punct$schars[300]$text$schars[304]$lpar%#$punct:$text%~$rpar$schars[304]$punct-$reset " 
 
-  PS2="$parens$char_304$text$char_304$punct-$reset "
+  PS2="$parens$schars[304]$text$schars[304]$punct-$reset "
 
-  precmd () { setopt promptsubst }
-  preexec () { }
+  prompt_opts=(cr subst percent)
 }
 
 prompt_elite2_preview () {
Index: Functions/Prompts/prompt_elite_setup
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Prompts/prompt_elite_setup,v
retrieving revision 1.3
diff -u -r1.3 prompt_elite_setup
--- Functions/Prompts/prompt_elite_setup	14 Jun 2007 16:10:52 -0000	1.3
+++ Functions/Prompts/prompt_elite_setup	17 May 2008 22:36:10 -0000
@@ -21,15 +21,14 @@
   local text=${1:-'red'}
   local punctuation=${2:-'blue'}
 
-  local char_333 char_262 char_261 char_260
+  local -A schars
   autoload -U prompt_special_chars
   prompt_special_chars
 
-  PS1="%{$fg[$text]%}$char_332$char_304%{$fg[$punctuation]%}(%{$fg[$text]%}%n%{$fg[$punctuation]%}@%{$fg[$text]%}%m%{$fg[$punctuation]%})%{$fg[$text]%}-%{$fg[$punctuation]%}(%{$fg[$text]%}%D{%I:%M%P}%{$fg[$punctuation]%}-:-%{$fg[$text]%}%D{%m}%{$fg[$punctuation]$fg[$text]%}/%D{%d}%{$fg[$punctuation]%})%{$fg[$text]%}$char_304-%{$fg[$punctuation]]%}$char_371%{$fg[$text]%}-$char_371$char_371%{$fg[$punctuation]%}$char_372$prompt_newline%{$fg[$text]%}$char_300$char_304%{$fg[$punctuation]%}(%{$fg[$text]%}%1~%{$fg[$punctuation]%})%{$fg[$text]%}$char_304$char_371%{$fg[$punctuation]%}$char_372%{$reset_color%}"
+  PS1="%F{$text}$schars[332]$schars[304]%F{$punctuation}(%F{$text}%n%F{$punctuation}@%F{$text}%m%F{$punctuation})%F{$text}-%F{$punctuation}(%F{$text}%D{%I:%M%P}%F{$punctuation}-:-%F{$text}%D{%m}%F{$punctuation}%F{$text}/%D{%d}%F{$punctuation})%F{$text}$schars[304]-%F{$punctuation}$schars[371]%F{$text}-$schars[371]$schars[371]%F{$punctuation}$schars[372]$prompt_newline%F{$text}$schars[300]$schars[304]%F{$punctuation}(%F{$text}%1~%F{$punctuation})%F{$text}$schars[304]$schars[371]%F{$punctuation}$schars[372]%f"
   PS2="> "
 
-  precmd () { setopt promptsubst }
-  preexec () { }
+  prompt_opts=(cr subst percent)
 }
 
 prompt_elite_preview () {
Index: Functions/Prompts/prompt_fade_setup
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Prompts/prompt_fade_setup,v
retrieving revision 1.3
diff -u -r1.3 prompt_fade_setup
--- Functions/Prompts/prompt_fade_setup	14 Jun 2007 16:10:52 -0000	1.3
+++ Functions/Prompts/prompt_fade_setup	17 May 2008 22:36:10 -0000
@@ -27,15 +27,14 @@
   local userhost=${2:-'white'}
   local date=${3:-'white'}
 
-  local char_333 char_262 char_261 char_260
+  local -A schars
   autoload -U prompt_special_chars
   prompt_special_chars
 
-  PS1="%{$fg[$fadebar_cwd]$bg[$fadebar_cwd]$bold_color%}$char_333$char_262$char_261$char_260%{$fg[$userhost]$bg[$fadebar_cwd]$bold_color%}%n@%m%{$reset_color$fg[$fadebar_cwd]$bg[grey]%}$char_333$char_262$char_261$char_260%{$fg[$date]$bg[grey]$bold_color%} %D{%a %b %d} %D{%I:%M:%S%P} $prompt_newline%{$fg[$fadebar_cwd]$bg[grey]$bold_color%}%~/%{$reset_color%} "
-  PS2="%{$fg[$fadebar_cwd]$bg[grey]%}$char_333$char_262$char_261$char_260%{$reset_color%}>"
+  PS1="%F{$fadebar_cwd}%B%K{$fadebar_cwd}$schars[333]$schars[262]$schars[261]$schars[260]%F{$userhost}%K{$fadebar_cwd}%B%n@%m%b%F{$fadebar_cwd}%K{black}$schars[333]$schars[262]$schars[261]$schars[260]%F{$date}%K{black}%B %D{%a %b %d} %D{%I:%M:%S%P} $prompt_newline%F{fadebar_cwd}%K{black}%B%~/%b%k%f "
+  PS2="%F{$fadebar_cwd}%K{black}$schars[333]$schars[262]$schars[261]$schars[260]%f%k>"
 
-  precmd () { setopt promptsubst }
-  preexec () { }
+  prompt_opts=(cr subst percent)
 }
 
 prompt_fade_preview () {
Index: Functions/Prompts/prompt_fire_setup
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Prompts/prompt_fire_setup,v
retrieving revision 1.3
diff -u -r1.3 prompt_fire_setup
--- Functions/Prompts/prompt_fire_setup	14 Jun 2007 16:10:52 -0000	1.3
+++ Functions/Prompts/prompt_fire_setup	17 May 2008 22:36:10 -0000
@@ -29,25 +29,24 @@
   local date=${5:-'white'}
   local cwd=${6:-'yellow'}
 
-  local char_333 char_262 char_261 char_260
+  local -a schars
   autoload -U prompt_special_chars
   prompt_special_chars
 
-  local GRAD1="%{$char_333$char_262$char_261$char_260%}"
-  local GRAD2="%{$char_260$char_261$char_262$char_333%}"
-  local COLOR1="%{$bold_color$fg[$fire1]$bg[$fire2]%}"
-  local COLOR2="%{$bold_color$fg[$userhost]$bg[$fire2]%}"
-  local COLOR3="%{$reset_color$fg[$fire3]$bg[$fire2]%}"
-  local COLOR4="%{$reset_color$fg[$fire3]$bg[grey]%}"
-  local COLOR5="%{$bold_color$fg[$cwd]$bg[grey]%}"
-  local COLOR6="%{$bold_color$fg[$date]$bg[grey]%}"
-  local GRAD0="%{$reset_color%}"
+  local GRAD1="%{$schars[333]$schars[262]$schars[261]$schars[260]%}"
+  local GRAD2="%{$schars[260]$schars[261]$schars[262]$schars[333]%}"
+  local COLOR1="%B%F{$fire1}%K{$fire2}"
+  local COLOR2="%B%F{$userhost}%K{$fire2}"
+  local COLOR3="%b%F{$fire3}%K{$fire2}"
+  local COLOR4="%b%F{$fire3}%K{black}"
+  local COLOR5="%B%F{$cwd}%K{black}"
+  local COLOR6="%B%F{$date}%K{black}"
+  local GRAD0="%b%f%k"
 
   PS1=$COLOR1$GRAD1$COLOR2'%n@%m'$COLOR3$GRAD2$COLOR4$GRAD1$COLOR6' %D{%a %b %d} %D{%I:%M:%S%P} '$prompt_newline$COLOR5'%~/'$GRAD0' '
   PS2=$COLOR1$GRAD1$COLOR3$GRAD2$COLOR4$GRAD1$COLOR5'>'$GRAD0' '
 
-  precmd () { setopt promptsubst }
-  preexec () { }
+  prompt_opts=(cr subst percent)
 }
 
 prompt_fire_preview () {
Index: Functions/Prompts/prompt_off_setup
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Prompts/prompt_off_setup,v
retrieving revision 1.2
diff -u -r1.2 prompt_off_setup
--- Functions/Prompts/prompt_off_setup	12 Jun 2007 15:51:41 -0000	1.2
+++ Functions/Prompts/prompt_off_setup	17 May 2008 22:36:10 -0000
@@ -4,8 +4,6 @@
   PS2="> "
 
   prompt_opts=( cr percent )
-  precmd () { }
-  preexec () { }
 }
 
 prompt_off_setup "$@"
Index: Functions/Prompts/prompt_oliver_setup
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Prompts/prompt_oliver_setup,v
retrieving revision 1.4
diff -u -r1.4 prompt_oliver_setup
--- Functions/Prompts/prompt_oliver_setup	7 May 2008 20:38:51 -0000	1.4
+++ Functions/Prompts/prompt_oliver_setup	17 May 2008 22:36:10 -0000
@@ -24,18 +24,18 @@
   [[ "${(t)pcolour}" != assoc* ]] && typeset -Ag pcolour
   [[ "${(t)tcolour}" != assoc* ]] && typeset -Ag tcolour
   local pcol=${1:-${pcolour[${HOST:=`hostname`}]:-bold}}
-  local pcolr=$fg[${pcol#bold}]
+  local pcolr="%F{${${pcol#bold}:-default}}"
   [[ $pcol = bold* ]] && pcolr=%B$pcolr
-  
+
   local tcol=${2:-${tcolour[$HOST]}}
-  local tcolr="fg=${tcol#bold}"
+  local tcolr="fg=${${tcol#bold}:-default}"
   [[ $tcol = bold* ]] && tcolr=bold,$tcolr
-  
+
   local a host="%m:" user="%n "
   [[ $HOST == (${(j(|))~normal_hosts}) ]] && host=""
   [[ $LOGNAME == (root|${(j(|))~normal_users}) ]] && user=""
 
-  PS1="%{$pcolr%}$user$host%~%"'$((COLUMNS-12))'"(l.$prompt_newline. )[%h%1(j.%%%j.)%0(?..:%?)]%# %{$reset_color%}"  RPS2='<%^'
+  PS1="$pcolr$user$host%~%"'$((COLUMNS-12))'"(l.$prompt_newline. )[%h%1(j.%%%j.)%0(?..:%?)]%# %b%f%k"  RPS2='<%^'
   PS2=''
   zle_highlight[(r)default:*]=default:$tcolr
 }
Index: Functions/Prompts/prompt_pws_setup
===================================================================
RCS file: Functions/Prompts/prompt_pws_setup
diff -N Functions/Prompts/prompt_pws_setup
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Functions/Prompts/prompt_pws_setup	17 May 2008 22:36:10 -0000
@@ -0,0 +1,22 @@
+# pws prompt theme
+
+prompt_pws_help() {
+    cat <<'EOF'
+Simple prompt which tries to display only the information you need.
+- highlighted parenthesised status if last command had non-zero status
+- bold + if shell is not at top level (may need tweaking if there
+  is another shell in the process history of your terminal)
+- number of background jobs in square brackets if non-zero
+- time in yellow on black, with Ding! on the hour.
+I usually use this in a white on black terminal.
+EOF
+}
+
+prompt_pws_setup() {
+      PS1='%K{white}%F{red}%(?..(%?%))'\
+'%K{black}%F{white}%B%(2L.+.)%(1j.[%j].)'\
+'%F{yellow}%(t.Ding!.%D{%L:%M})'\
+'%f%k%b%# '
+}
+
+prompt_pws_setup "$@"
Index: Functions/Prompts/prompt_redhat_setup
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Prompts/prompt_redhat_setup,v
retrieving revision 1.2
diff -u -r1.2 prompt_redhat_setup
--- Functions/Prompts/prompt_redhat_setup	3 Jul 2007 17:06:06 -0000	1.2
+++ Functions/Prompts/prompt_redhat_setup	17 May 2008 22:36:10 -0000
@@ -7,8 +7,6 @@
   PS2="> "
 
   prompt_opts=( cr percent )
-  precmd () { }
-  preexec () { }
 }
 
 prompt_redhat_setup "$@"
Index: Functions/Prompts/prompt_special_chars
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Prompts/prompt_special_chars,v
retrieving revision 1.1
diff -u -r1.1 prompt_special_chars
--- Functions/Prompts/prompt_special_chars	14 Jun 2007 16:10:52 -0000	1.1
+++ Functions/Prompts/prompt_special_chars	17 May 2008 22:36:10 -0000
@@ -6,13 +6,20 @@
 # We still provide them in that form if the current character
 # set isn't UTF-8.  We could in principle use iconv if available.
 
+typeset -gA schars
+
 if [[ ${LC_ALL:-${LC_CTYPE:-$LANG}} = *UTF-8* ]]; then
-  char_333=$'\xe2\x96\x88'
-  char_262=$'\xe2\x96\x93'
-  char_261=$'\xe2\x96\x92'
-  char_260=$'\xe2\x96\x91'
+  schars[300]=$'\xe2\x94\x94'
+  schars[304]=$'\xe2\x94\x8c'
+  schars[332]=$'\xe2\x94\x8c'
+  schars[333]=$'\xe2\x96\x88'
+  schars[371]=$'\xc2\xa8'
+  schars[372]=$'\xcb\x99'
+  schars[262]=$'\xe2\x96\x93'
+  schars[261]=$'\xe2\x96\x92'
+  schars[260]=$'\xe2\x96\x91'
 else
-  for code in 333 262 261 260; do
-    char_$code=$(echo -n "\\0$code")
+  for code in 300 304 332 333 371 372 262 261 260; do
+    eval "char[$code]=\$'\\$code'"
   done
 fi
Index: Functions/Prompts/prompt_suse_setup
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Prompts/prompt_suse_setup,v
retrieving revision 1.2
diff -u -r1.2 prompt_suse_setup
--- Functions/Prompts/prompt_suse_setup	3 Jul 2007 17:06:06 -0000	1.2
+++ Functions/Prompts/prompt_suse_setup	17 May 2008 22:36:10 -0000
@@ -7,8 +7,6 @@
   PS2="> "
 
   prompt_opts=( cr percent )
-  precmd () { }
-  preexec () { }
 }
 
 prompt_suse_setup "$@"
Index: Functions/Prompts/prompt_walters_setup
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Prompts/prompt_walters_setup,v
retrieving revision 1.1
diff -u -r1.1 prompt_walters_setup
--- Functions/Prompts/prompt_walters_setup	7 Feb 2002 07:35:15 -0000	1.1
+++ Functions/Prompts/prompt_walters_setup	17 May 2008 22:36:10 -0000
@@ -15,11 +15,12 @@
 
 if [[ "$TERM" != "dumb" ]]; then
     export PROMPT='%B%(?..[%?] )%b%n@%U%m%u> '
-    export RPROMPT="%{$fg_no_bold[${1:-green}]%}%~%{$reset_color%}"
+    export RPROMPT="%F{${1:-green}}%~%f"
 else
     export PROMPT="%(?..[%?] )%n@%m:%~> "
 fi
 
+  prompt_opts=(cr percent)
 }
 
 prompt_walters_setup "$@"
Index: Functions/Prompts/prompt_zefram_setup
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Prompts/prompt_zefram_setup,v
retrieving revision 1.2
diff -u -r1.2 prompt_zefram_setup
--- Functions/Prompts/prompt_zefram_setup	7 Sep 2006 18:09:44 -0000	1.2
+++ Functions/Prompts/prompt_zefram_setup	17 May 2008 22:36:10 -0000
@@ -12,8 +12,8 @@
   PS2='%(4_:... :)%3_> '
 
   prompt_opts=( cr subst percent )
-  precmd () { prompt_zefram_precmd }
-  preexec () { }
+
+  add-zsh-hook precmd prompt_zefram_precmd
 }
 
 prompt_zefram_setup "$@"
Index: Functions/Prompts/promptinit
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Prompts/promptinit,v
retrieving revision 1.7
diff -u -r1.7 promptinit
--- Functions/Prompts/promptinit	31 Oct 2007 16:03:07 -0000	1.7
+++ Functions/Prompts/promptinit	17 May 2008 22:36:10 -0000
@@ -30,9 +30,8 @@
     fi
   done
 
-  # Color definitions come in handy
-  autoload -U colors
-  colors
+  # To manipulate precmd and preexec hooks...
+  autoload -U add-zsh-hook
 
   # Variables common to all prompt styles
   prompt_newline=$'\n%{\r%}'
@@ -40,7 +39,7 @@
 
 prompt_preview_safely() {
   emulate -L zsh
-  print $reset_color
+  print -P "%b%f%k"
   if [[ -z "$prompt_themes[(r)$1]" ]]; then
     print "Unknown theme: $1"
     return
@@ -48,7 +47,7 @@
 
   local -a psv; psv=($psvar); local -a +h psvar; psvar=($psv) # Ick
   local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1
-  trap "${$(functions precmd):-:} ; ${$(functions preexec):-:}" 0
+  local -a precmd_functions preexec_functions
 
   # The next line is a bit ugly.  It (perhaps unnecessarily)
   # runs the prompt theme setup function to ensure that if
@@ -85,7 +84,7 @@
         # Not using a prompt theme; save settings
         local -a psv; psv=($psvar); local -a +h psvar; psvar=($psv) # Ick
 	local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1
-	trap "${$(functions precmd):-:} ; ${$(functions preexec):-:}" 0
+	local precmd_functions preexec_functions
       else
         trap 'prompt_${prompt_theme[1]}_setup "${(@)prompt_theme[2,-1]}"' 0
       fi
@@ -130,7 +129,7 @@
          [[ "$theme" == "$prompt_theme[*]" ]] && continue
          prompt_preview_safely "$=theme"
        done
-       print $reset_color
+       print -P "%b%f%k"
        ;;
     s) print "Set and save not yet implemented.  Please ensure your ~/.zshrc"
        print "contains something similar to the following:\n"
@@ -153,21 +152,21 @@
          print "$usage"
          return
        fi
-       prompt_$1_setup "$@[2,-1]" && prompt_theme=( "$@" )
 
-       # Avoid screwing up the environment listing
-       PSZZZZ=$reset_color
-       RPSZZZZ=$reset_color
-       PROMPTZZZZ=$reset_color
-       RPROMPTZZZZ=$reset_color
-       promptzzzz=$reset_color
+       # Reset some commonly altered bits to the default
+       add-zsh-hook -D precmd "prompt_*_precmd"
+       add-zsh-hook -D preexec "prompt_*_preexec"
+       set -A zle_highlight ${zle_highlight:#default:*}
+       (( ${#zle_highlight} )) || unset zle_highlight
+
+       prompt_$1_setup "$@[2,-1]" && prompt_theme=( "$@" )
        ;;
   esac
 }
 
 prompt () {
   local prompt_opts
-  
+
   set_prompt "$@"
  
   (( $#prompt_opts )) &&
@@ -180,16 +179,18 @@
   emulate -L zsh
   local -a psv; psv=($psvar); local -a +h psvar; psvar=($psv) # Ick
   local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1
-  trap "${$(functions precmd):-:} ; ${$(functions preexec):-:}" 0
+  local precmd_functions preexec_functions
 
   print -n "$1 theme"
   (( $#* > 1 )) && print -n " with parameters \`$*[2,-1]'"
   print ":"
   prompt_${1}_setup "$@[2,-1]"
-  typeset +f precmd >&- && precmd
+  [[ -n ${precmd_functions[(r)prompt_${1}_precmd]} ]] &&
+    prompt_${1}_precmd
   [[ -o promptcr ]] && print -n $'\r'; :
   print -P "${PS1}command arg1 arg2 ... argn"
-  typeset +f preexec >&- && preexec
+  [[ -n ${preexec_functions[(r)prompt_${1}_preexec]} ]] &&
+    prompt_${1}_preexec
 }
 
 [[ -o kshautoload ]] || promptinit "$@"

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



Messages sorted by: Reverse Date, Date, Thread, Author