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

Re: What's a superjob?



On Wed, Sep 26, 2018 at 8:51 AM Peter Stephenson
<p.stephenson@xxxxxxxxxxx> wrote:
>
> Now we have just one process running: the main shell, and vi.  Suppose
> you hit ^Z.  Then vi suspends.  The main shell is in the middle of
> running e, but it's not supposed to finish doing that till vi exits.
> But without special action we're now back at the top-level shell prompt
> and it never will execute.

To add a bit more color here ... in the absence of this special
handling, when vi is suspended, the shell has two choices:
1) treat vi as successfully completed and continue executing the function, or
2) treat vi as failed and stop the function at this point.

IIRC different shells have historically made different decisions about
this.  I believe zsh's original behavior was #1, but that led to
problems if (in this type of example) the remainder of the function
depends on the content of the edited file.  So #2 avoids side-effects,
but causes at minimum annoyance because now you have a suspended vi
but the rest of the function is simply gone.

The other possibility is to immediately fork the whole function as
soon as any non-builtin command is encountered, and then have the
forked function fork again for the external job, to keep the process
tree "normal".  This would simplify the job handling in the main
shell, but ruin the intention of the function being able to affect the
main shell context in the case where no job control ever occurs.



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