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

Re: precmd, preexec, and supplied prompt themes



Bart Schaefer wrote:
> So some discussion of how this ought to be redesigned would be useful
> before someone jumps in to do it.  It's always seemed a bit clunky to
> me to do build up function names by sticking the theme name in the
> middle, but that's at nit-pick.  Maybe all we need is another one of
> those functions, prompt_ZZZ_off (or pick another word).

We could do it with one level of indirection...


Generically:

if [[ -z ${precmd_functions[(R)precmd_prompt]} ]]; then
  precmd_functions+=(precmd_prompt)
fi
precmd_prompt() {
   if (( ${+prompt_functions[precmd]} )); then
     $prompt_functions[precmd]
   fi
}


For each prompt:

typeset -gA prompt_function_hooks
prompt_functions=(precmd my_fantastic_precmd_function
                  setup my_absolutely_superb_setup_function
                  teardown my_truly_wonderful_teardown_function)


and so on.  As long as the functions in question are defined at the same
time as the prompt_functions associative array there isn't a
namespace clash.

-- 
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