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

Re: Teardown for prompts



On Jan 5, 11:23am, Christian Holtje wrote:
}
} 1) Remove other prompt related hooks. Currently, it removes preexec
} and precmd, but it doesn't remove chpwd, periodic, zshexit, nor
} zshaddhistory.
}       e.g.
} for hook in preexec precmd chpwd periodic zshexit zshaddhistory; do

I was looking again at the patch you sent for this, and for prompts it
seems it might be important to handle the zsh_directory_name hook too.

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

    for hook in ${=${(f)"$(add-zsh-hook)"}[-1]}

would do it, though it might be better to add a -L option to add-zsh-hook
so as not to rely on the usage message and that being printed to stdout.

There's actually a similar issue with prompt_preview_theme, which tries
to make hook lists local to prevent them from changing the world when a
prompt is "temporarily" installed.

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

If added, this should probably use "cleanup" rather than "teardown" to
be consistent with other zsh usages.

There's an example of something like this in prompt_bart_setup, where
you can say "prompt bart off" and it unloads itself.  A comment in there
seems to indicate that at one time there was a theme named "off" so you
could just say "prompt off" and it would unload everything, but I can't
find any other trace of the "prompt_off_setup" function any longer.

}  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 think I'd rather leave this up to the individual cleanup routines.



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