From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20132 invoked from network); 20 Oct 1999 06:48:21 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 20 Oct 1999 06:48:21 -0000 Received: (qmail 4993 invoked by alias); 20 Oct 1999 06:48:16 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8337 Received: (qmail 4975 invoked from network); 20 Oct 1999 06:48:14 -0000 From: "Bart Schaefer" Message-Id: <991020041621.ZM6569@candle.brasslantern.com> Date: Wed, 20 Oct 1999 04:16:21 +0000 In-Reply-To: <380CC25A.BC019EC7@u.genie.co.uk> Comments: In reply to Oliver Kiddle "PATCH: New prompt themes" (Oct 19, 8:11pm) References: <380CC25A.BC019EC7@u.genie.co.uk> X-Mailer: Z-Mail (5.0.0 30July97) To: Zsh workers Subject: Alternate patch Re: PATCH: New prompt themes MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Oct 19, 8:11pm, Oliver Kiddle wrote: } Subject: PATCH: New prompt themes } } The trouble is that the prompt function uses emulate -L so I can't set } options in my prompt setup function. The following patch is a possible } solution. It uses an associative array to return the prompt options to } a wrapper function which sets them. For example, you can do: } prompt_opts=( subst set percent set bang unset ) There doesn't seem to be any reason to put the set_prompt function inside the prompt function, so I suggest the following smaller patch. It's the same code Oliver sent, without a lot of the reindentation, so it would be used in place of Oliver's original. I'm not sure that it's that useful to factor out the prefix "prompt" from each of the strings in prompt_opts, but I'm not going to change that here. Further, I might suggest that instead of an assoc. array with both set and unset values, just use a regular array of only the values that are meant to be set; e.g. one command instead of a loop: setopt noprompt{bang,cr,percent,subst} prompt$^prompt_opts However, I didn't make that change either. Index: Functions/Prompts/promptinit =================================================================== @@ -34,7 +34,7 @@ prompt_newline=$(echo -ne "\n%{\r%}") } -prompt () { +set_prompt() { emulate -L zsh local opt preview theme usage old_theme @@ -103,6 +103,23 @@ promptzzzz=$reset_color ;; esac +} + +prompt () { + local -A prompt_opts + local opt + + set_prompt "$@" + + # Set prompt options + for opt in ${(k)prompt_opts}; do + if [[ $prompt_opts[$opt] != (|un)set ]]; then + echo "${0##*/}: value of prompt option must be 'set' or 'unset'" >&2 + return 1 + else + $prompt_opts[$opt]opt prompt$opt + fi + done } promptinit "$@" -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com