Subject: Re: prompt update and TRAPCHLD
From: Vincent Lefevre <[email-masked]>
To: [email-masked]
Date: Fri, 22 Jan 2016 02:42:29 +0100
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On 2016-01-21 11:13:55 -0800, Bart Schaefer wrote:
> The rule actually is that traps are executed as early as it is "safe" to
> do so (memory management, etc.), and one of those times is immediately
> before another command is going to be run; so the trap could execute for
> example at any time during your precmd function, or during zle-line-init,
> etc.
> 
> So in that sense yes, there is a race condition.

The following code solves it:

updprompt()
{
  unset _trapchld_called
  [...]
  [[ -n $_trapchld_called ]] && updprompt
}

TRAPCHLD()
{
  if [[ -o interactive && -n $TTY ]] then
    {
      updprompt
      typeset -g _trapchld_called=1
    }
  fi
}

-- 
Vincent Lefèvre <[email-masked]> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)