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

Teardown for prompts

I have some suggestions for the promptinit stuff....  

1) Remove other prompt related hooks.  Currently, it removes preexec and precmd, but it doesn't remove chpwd, periodic, zshexit, nor zshaddhistory.
for hook in preexec precmd chpwd periodic zshexit zshaddhistory; do
          add-zsh-hook -D "${hook}" "prompt_*_${hook}"

     Bonus points for getting the list of hooks from add-zsh-hook itself.

 2) Add a teardown function.  This could be used to unset things, etc. if the prompt changes.  If prompt is switching from the prompt 'adam2', it would look for prompt_adam2_teardown and run it if it exists before switch to the new prompt.

 3) On switching away from a prompt, look for any and all variables and functions with pattern "prompt_${current_prompt_name}_*" and unset/unfunction them.

I discovered this when I wrote a prompt that used the chpwd hook to try to minimize certain VCS checks (an optimization) and that function was still being called when I switched to a new prompt.  

Christian Höltje

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