From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16807 invoked by alias); 22 Apr 2015 20:47:39 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 34948 Received: (qmail 10366 invoked from network); 22 Apr 2015 20:47:33 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-Originating-IP: [80.3.228.158] X-Spam: 0 X-Authority: v=2.1 cv=RcseCjdv c=1 sm=1 tr=0 a=P+FLVI8RzFchTbbqTxIDRw==:117 a=P+FLVI8RzFchTbbqTxIDRw==:17 a=kj9zAlcOel0A:10 a=NLZqzBF-AAAA:8 a=4IWuy7rYpfo8T5FZ3TMA:9 a=CjuIK1q_8ugA:10 Date: Wed, 22 Apr 2015 21:41:55 +0100 From: Peter Stephenson To: Zsh Hackers' List Subject: Re: Using "source" in a function breaks job control Message-ID: <20150422214155.67ece429@ntlworld.com> In-Reply-To: <5537E450.9060205@thequod.de> References: <5537E450.9060205@thequod.de> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 22 Apr 2015 20:11:28 +0200 Daniel Hahler 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