Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Teardown for prompts [patch - remove all hooks]
- X-seq: zsh-workers 30087
- From: Christian Höltje <docwhat@xxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: Teardown for prompts [patch - remove all hooks]
- Date: Thu, 5 Jan 2012 13:44:31 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:date:from:to:message-id:in-reply-to:references:subject :x-mailer:mime-version:content-type; bh=BOzK2Ly8+/pPyrMAQmTurmz8Dqqp0+0+98+1alnRSYo=; b=L6kAX8jDLqy6jjPBjtsg4QaTA7I5kmxhRkNpiQaOmSXLJL0LLQzNyNtyoukb+Pufnd eWAfASBJ8RucKtHQO+zoq72HtMpAZt+IdfrUdKEIuF0TOw5JvfxvaMfOAjVFVQQDy7ft 1kLCmsDzO9GUz23cUBtv4jI0TfeMvjvZ7Ozb8=
- In-reply-to: <B3BC4505B3444C2EAEEF95F8B334D14F@gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <B3BC4505B3444C2EAEEF95F8B334D14F@gmail.com>
- Sender: Christian Höltje <docwhat@xxxxxxxxx>
This patch will remove all prompt hooks when changing prompts, using the prompt system.
The current code only catches the precmd and preexec hooks, but all the hooks should be checked.
diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit
index b07eabb..66e73a7 100644
--- a/Functions/Prompts/promptinit
+++ b/Functions/Prompts/promptinit
@@ -155,8 +155,10 @@ Use prompt -h <theme> for help on specific themes.'
fi
# Reset some commonly altered bits to the default
- add-zsh-hook -D precmd "prompt_*_precmd"
- add-zsh-hook -D preexec "prompt_*_preexec"
+ local hook
+ for hook in chpwd precmd preexec periodic zshaddhistory zshexit; do
+ add-zsh-hook -D "${hook}" "prompt_*_${hook}"
+ done
set -A zle_highlight ${zle_highlight:#default:*}
(( ${#zle_highlight} )) || unset zle_highlight
--
Christian Höltje
docwhat@xxxxxxxx
http://docwhat.org/
On Thursday, January 5, 2012 at 11:23 AM, Christian Höltje wrote:
> 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.
> e.g.
> for hook in preexec precmd chpwd periodic zshexit zshaddhistory; do
> add-zsh-hook -D "${hook}" "prompt_*_${hook}"
> done
>
> 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
> docwhat@xxxxxxxx (mailto:docwhat@xxxxxxxx)
> http://docwhat.org/
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author