From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29455 invoked from network); 19 Nov 1999 09:07:55 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 19 Nov 1999 09:07:55 -0000 Received: (qmail 6296 invoked by alias); 19 Nov 1999 09:02:27 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8672 Received: (qmail 24559 invoked from network); 19 Nov 1999 01:51:47 -0000 Date: Fri, 19 Nov 1999 01:51:43 +0000 From: Adam Spiers To: zsh workers mailing list Subject: Re: PATCH: prompt theme system improvements Message-ID: <19991119015143.A29956@thelonious.new.ox.ac.uk> Reply-To: Adam Spiers Mail-Followup-To: zsh workers mailing list References: <19991118145330.A22718@thelonious.new.ox.ac.uk> <991118175142.ZM9631@candle.brasslantern.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0pre3i In-Reply-To: <991118175142.ZM9631@candle.brasslantern.com> X-URL: http://www.new.ox.ac.uk/~adam/ X-OS: Linux 2.2.12 i686 Bart Schaefer (schaefer@candle.brasslantern.com) wrote: > On Nov 18, 2:53pm, Adam Spiers wrote: > } Subject: PATCH: prompt theme system improvements > } > } OK, finally here's a patch to the prompt system which vastly improves > } it. > > I was just fooling with this, and after running > > prompt -p > > I get the message > > set_prompt: command not found: prompt__setup [71] Doh. The p) if (( ! $+prompt_theme )); then print "Cannot preview; current prompt is non-themeable and would" print "be destroyed." return fi bit should have caught this, but I'd already declared prompt_theme so the test went wrong. However, it's pretty bad that you can't preview any themes until you're using one, so this patch changes that, and restores PS[1-4], RPS1 and pre{cmd,exec} to their original values after the preview if $prompt_theme wasn't set. It also fixes some other bugs I found. N.B. I forgot to mention that that last patch added the following files: Functions/Prompts/prompt_bigfade_setup Functions/Prompts/prompt_fade_setup Functions/Prompts/prompt_zefram_setup Tanaka, can you please add them to the CVS repository? Sorry! The following patch also fixes the relevant .distfiles. Index: Functions/Prompts/.distfiles =================================================================== RCS file: /projects/zsh/zsh/Functions/Prompts/.distfiles,v retrieving revision 1.1.1.2 diff -u -r1.1.1.2 .distfiles --- Functions/Prompts/.distfiles 1999/11/03 09:06:29 1.1.1.2 +++ Functions/Prompts/.distfiles 1999/11/19 01:46:15 @@ -1,9 +1,8 @@ DISTFILES_SRC=' .distfiles - prompt_elite2_setup prompt_red_setup prompt_adam1_setup + prompt_elite2_setup prompt_adam1_setup prompt_fade_setup prompt_elite_setup prompt_redhat_setup prompt_adam2_setup - prompt_fire_setup prompt_suse_setup prompt_blue_setup - prompt_green_setup prompt_white_setup prompt_combo_setup - prompt_magenta_setup prompt_yellow_setup prompt_cyan_setup - prompt_oliver_setup prompt_off_setup promptinit + prompt_fire_setup prompt_suse_setup prompt_bigfade_setup + prompt_oliver_setup prompt_off_setup prompt_zefram_setup + promptinit ' Index: Functions/Prompts/prompt_adam2_setup =================================================================== RCS file: /projects/zsh/zsh/Functions/Prompts/prompt_adam2_setup,v retrieving revision 1.1.1.3 diff -u -r1.1.1.3 prompt_adam2_setup --- Functions/Prompts/prompt_adam2_setup 1999/11/18 15:15:27 1.1.1.3 +++ Functions/Prompts/prompt_adam2_setup 1999/11/19 01:46:16 @@ -46,20 +46,17 @@ # This is a cute hack. Well I like it, anyway. prompt_gfx_bbox_to_mbox=$(print -n "%{\e[A\r$fg_bold[$prompt_adam2_color1]${prompt_gfx_mlc}$fg_no_bold[$prompt_adam2_color1]${prompt_gfx_hyphen}\e[B%}") - prompt_l_paren=$'%{$fg_bold[grey]%}(' - prompt_r_paren=$'%{$fg_bold[grey]%})' + prompt_l_paren="%{$fg_bold[grey]%}(" + prompt_r_paren="%{$fg_bold[grey]%})" - prompt_l_bracket=$'%{$fg_bold[grey]%}[' - prompt_r_bracket=$'%{$fg_bold[grey]%}]' - prompt_machine="%{$fg_no_bold[$prompt_adam2_color3]%}%n%{$fg_bold[$prompt_adam2_color3]%}@%{$fg_no_bold[$prompt_adam2_color3]%}%m" prompt_padding_text=`perl -e "print qq{${prompt_gfx_hyphen}} x 200"` 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_1a_no_color=$(echo "$prompt_line_1a" | perl -pe "s/%{.*?%}//g") + prompt_line_1a_no_color=$(echo "$prompt_line_1a" | perl -pe 's/%{.*?%}//g') prompt_line_1b="$prompt_l_paren$prompt_machine$prompt_r_paren%{$fg_no_bold[$prompt_adam2_color1]%}${prompt_gfx_hyphen}" - prompt_line_1b_no_color=$(echo "$prompt_line_1b" | perl -pe "s/%{.*?%}//g") + prompt_line_1b_no_color=$(echo "$prompt_line_1b" | perl -pe 's/%{.*?%}//g') prompt_line_2="$prompt_gfx_bbox${prompt_gfx_hyphen}%{$fg_bold[white]%}" Index: Functions/Prompts/prompt_fire_setup =================================================================== RCS file: /projects/zsh/zsh/Functions/Prompts/prompt_fire_setup,v retrieving revision 1.1.1.3 diff -u -r1.1.1.3 prompt_fire_setup --- Functions/Prompts/prompt_fire_setup 1999/11/18 15:15:27 1.1.1.3 +++ Functions/Prompts/prompt_fire_setup 1999/11/19 01:46:16 @@ -43,7 +43,7 @@ local COLOR6="%{$bold_color$fg[$date]$bg[grey]%}" local GRAD0="%{$reset_color%}" - PS1=$COLOR1$GRAD1$COLOR2'%n@%m'$COLOR3$GRAD2$COLOR4$GRAD1$COLOR6' %D{%a %b %d} %D{%I:%M:%S%P} '$NONE'$prompt_newline'$COLOR5'%~/'$GRAD0' ' + PS1=$COLOR1$GRAD1$COLOR2'%n@%m'$COLOR3$GRAD2$COLOR4$GRAD1$COLOR6' %D{%a %b %d} %D{%I:%M:%S%P} '$NONE$prompt_newline$COLOR5'%~/'$GRAD0' ' PS2=$COLOR1$GRAD1$COLOR3$GRAD2$COLOR4$GRAD1$COLOR5'>'$GRAD0' ' precmd () { setopt promptsubst } Index: Functions/Prompts/promptinit =================================================================== RCS file: /projects/zsh/zsh/Functions/Prompts/promptinit,v retrieving revision 1.1.1.8 diff -u -r1.1.1.8 promptinit --- Functions/Prompts/promptinit 1999/11/18 15:15:27 1.1.1.8 +++ Functions/Prompts/promptinit 1999/11/19 01:46:28 @@ -81,10 +81,11 @@ print $prompt_themes return ;; - p) if (( ! $+prompt_theme )); then - print "Cannot preview; current prompt is non-themeable and would" - print "be destroyed." - return + p) if [[ -z "$prompt_theme[1]" ]]; then + # Not using a prompt theme; save settings + prompt_non_theme=( "$PS1" "$PS2" "$PS3" "$PS4" "$RPS1" ) + prompt_old_precmd="$(functions precmd)" + prompt_old_preexec="$(functions preexec)" fi preview=( $prompt_themes ) (( $#* > 1 )) && preview=( "$@[2,-1]" ) @@ -97,10 +98,10 @@ fi print - # The next line is a bit ugly. It (perhaps unnecessarily) - # runs the prompt theme setup function to ensure that if - # the theme has a _preview function that it's been autoloaded. - prompt_${theme_args[1]}_setup + # The next line is a bit ugly. It (perhaps unnecessarily) + # runs the prompt theme setup function to ensure that if + # the theme has a _preview function that it's been autoloaded. + prompt_${theme_args[1]}_setup if functions prompt_${theme_args[1]}_preview >&/dev/null; then prompt_${theme_args[1]}_preview "${(@)theme_args[2,-1]}" @@ -109,7 +110,25 @@ fi done print - prompt_${prompt_theme[1]}_setup "${(@)prompt_theme[2,-1]}" + if [[ -z "$prompt_theme[1]" ]]; then + PS1="$prompt_non_theme[1]" + PS2="$prompt_non_theme[2]" + PS3="$prompt_non_theme[3]" + PS4="$prompt_non_theme[4]" + RPS1="$prompt_non_theme[5]" + if [[ -z "$prompt_old_precmd" ]]; then + precmd () { } + else + eval "$prompt_old_precmd" + fi + if [[ -z "$prompt_old_preexec" ]]; then + preexec () { } + else + eval "$prompt_old_preexec" + fi + else + prompt_${prompt_theme[1]}_setup "${(@)prompt_theme[2,-1]}" + fi ;; s) print "Set and save not yet implemented. Please ensure your ~/.zshrc" print "contains something similar to the following:\n" @@ -118,12 +137,12 @@ print " prompt $*[2,-1]" ;; *) if [[ "$1" == 'random' ]]; then - local random_themes - if (( $#* == 1 )); then - random_themes=( $prompt_themes ) - else - random_themes=( "$@[2,-1]" ) - fi + local random_themes + if (( $#* == 1 )); then + random_themes=( $prompt_themes ) + else + random_themes=( "$@[2,-1]" ) + fi local i=$(( ( $RANDOM % $#random_themes ) + 1 )) argv=( "${=random_themes[$i]}" ) fi