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

Re: jobs command in precmd



> Hello *,
> 
> When I put the 'jobs' builtin command in my precmd function, zsh
> exits immediately without giving me a warning that I still have
> background jobs.
> 
> I found out that zsh exits without a warning if the previous command
> was the jobs command.
> 
> But in my precmd function there are many commands after the jobs
> command.

The shell has a flag (which happens to be called stopmsg) to tell it that
you've just looked at your jobs, and hence don't need to be warned again.
The main use of this is that you need to be able to ignore the `you have
XXX jobs' messages, otherwise you couldn't leave the shell at all.
However, it's assumed that the `jobs' command also tells you all you need
to know, so you can exit straight after.  (You probably know all this.)

The real difficulty is that the stopmsg is only reset when the shell gets
back to the main command loop, i.e. after executing some block of
commands on a single line.  Arguably this is correct as far as it goes,
since it doesn't matter how you see the message from `jobs' --- for
example, you might have buried it inside your own shell function.  But the
case of precmd is a bit special, since effectively it all happens without
your knowing.  Maybe simply saving and restoring stopmsg when executing
precmd would be enough.  I don't have time to go into the details right
now, however.



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