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.

I'm not going to get any further with this tonight, but using a build to
instrument process group handling I posted a few weeks ago it seems that
in the failing case the terminal doesn't get reattached to the vim
process when the shell function is brought to the foreground.

I've omitted irrelevant detail, in particular attaching to the main
interactive shell process.

In the successful case,


+10:11% vi() { vim -u NONE -N; } 
+10:11% vi
Attaching TTY 10 to 20919
[1]  + 20922 suspended  vi
(148)+[1]10:11% ps -fp 20922 
UID        PID  PPID  C STIME TTY          TIME CMD
pws      20922 20794  0 22:11 pts/1    00:00:00 ./zsh
+[1]10:12% ps -fp 20919
UID        PID  PPID  C STIME TTY          TIME CMD
pws      20919 20794  0 22:11 pts/1    00:00:00 vim -u NONE -N
+[1]10:12% fg
[1]  + 20922 continued  vi
Attaching TTY 10 to 20919
Attaching TTY 10 to 20922


I suspect but haven't checked that final attachtty is after the vim
exited successfully (which you can't see happening).

In the failing case,


+10:12% vi() { . /tmp/foo.zsh; vim -u NONE -N; }
+10:13% vi
Attaching TTY 10 to 21065
[1]  + 21068 running    
(148)+[1]10:13% ps -fp 21068
UID        PID  PPID  C STIME TTY          TIME CMD
pws      21068 20794  0 22:13 pts/1    00:00:00 ./zsh
+[1]10:13% ps -fp 21065
UID        PID  PPID  C STIME TTY          TIME CMD
pws      21065 20794  0 22:13 pts/1    00:00:00 vim -u NONE -N
+[1]10:13% fg
[1]  + 21068 continued  
Attaching TTY 10 to 21068


There's no attachtty to 21065.  Handling of SIGCONT within the subshell?

pws



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