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

Re: Using "source" in a function breaks job control



On Wed, 22 Apr 2015 20:11:28 +0200
Daniel Hahler <genml+zsh-workers@xxxxxxxxxx> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> I've noticed that when using "source" (with a file that has at least
> one expression) 
> in a function, it will cause job control to not work as expected anymore.
> 
> TEST CASE:
> 1. echo true > /tmp/foo.zsh
> 2. vi() { source /tmp/foo.zsh; vim -u NONE -N; }
> 3. Run "vi"
> 4. In Vim, press Ctrl-Z to put it into the background.
> 5. Execute "fg".
>
> It should bring back "vim", but does not.

This may take some tracking down, but I suspect the "source" is
doing something to the current shell status that it's then not undoing.

> The PID 23415 refers to a "zsh" subprocess:
> 
>   |   |-zsh,23316
>   |   |   |-vim,23414 -u NONE -N
>   |   |   `-zsh,23415
> 
> Is this behavior expected?
> Why is there a new subprocess being created?

That bit's correct.  What you're suspending is the shell function, to do
which it has to fork a shell.  Try suspending and then foregrounding:

vi() {
   vim
   print "vim exited with status $?"
}

and you'll see that the last line would be executed in the wrong place
or not at all without that.  Unfortunately it seems to get the status
wrong: it's the one from when vim suspended rather than when it exited.

pws



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