Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: "{ } always { }" construct and return in called functions
- X-seq: zsh-workers 35212
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: "{ } always { }" construct and return in called functions
- Date: Tue, 19 May 2015 08:31:48 +0200
- Cc: zsh workers <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=N/sYxJVRX2dP7m3QbhcvYvxmWx7r2KaYvGqTIckFoiQ=; b=s4VCkaamXg6gEfzy8CpgNr19D67zh4qIhltXgqhcMIlok0ayRzre667tI8+W7X8Tie Kq92DJLvp6Iy0f5C6hQ7MGJ0If5RAZtKjyD5Bm2gWBPCT9ZfNS3Ts0W+AfSiGKQLYPFs xm4DMz89QC8OY+Bch6MFHF4xf5CxmnaxHBv7jwdajqNVX9V/ERvp9cBzE2Xaa/hKTtKG PBDgIQY1R8Yo9QJXt79lbbyeSJWHbjNp18sjdsj9Y7HqWQUcWyYXT2mQ4G3YkZWo6/Ts 1VW930wZtLtQgQqEqVGo1jDbKi3p8uEJ6QdrT3rzYiAkpS+b8U2v8On6sbOls+8tIF7T l/vA==
- In-reply-to: <CAHYJk3Qgm=Mc3_d+kC-1hB7ybxcqU43nnr7Hw=N-opXj7nDa8A@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAHfspHmUOgLjnEMtLBBoeU31Z2GKu8uD5MYE4jsogMKbf+ag9g@mail.gmail.com> <20150513155915.71f3daaa@pwslap01u.europe.root.pri> <CAHYJk3RBn_U_ZTNXWHeBfAJyibspcx1=gMM2OTmXz2cpsrrY2Q@mail.gmail.com> <20150518131401.2db3aefa@pwslap01u.europe.root.pri> <CAHYJk3QCxkpN_G2yAXW0S+J8BnV4O3OFTpPHAg9+ajuJ3RXb1A@mail.gmail.com> <20150518134704.0a7f4293@pwslap01u.europe.root.pri> <150518220408.ZM7475@torch.brasslantern.com> <CAHYJk3Qgm=Mc3_d+kC-1hB7ybxcqU43nnr7Hw=N-opXj7nDa8A@mail.gmail.com>
On Tue, May 19, 2015 at 8:22 AM, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> On Tue, May 19, 2015 at 7:04 AM, Bart Schaefer
> <schaefer@xxxxxxxxxxxxxxxx> wrote:
>> On May 18, 1:47pm, Peter Stephenson wrote:
>> } Subject: Re: "{ } always { }" construct and return in called functions
>> }
>> } Hmmm... I'm wondering if the fact you've started jobs is important. It
>> } shouldn't be, with the "&|", and the doshfunc() code is supposed
>> } to make it irrelevant anyway by setting "stopmsg = 1".
>>
>> If you have some other job running in the background, the shell does
>> not exit when 'exit' is called from a zle widget:
>>
>> torch% unsetopt correct
>> torch% function _accept_and_quit() {
>> function> local -a buf
>> function> buf=(${(z)BUFFER})
>> function> if which $buf[1] >& /dev/null; then
>> function then> zsh -c "${BUFFER}" &|
>> function then> exit
>> function then> else
>> function else> zle -M "Command $buf[1] not found"
>> function else> fi
>> function> }
>> torch% zle -N _accept_and_quit
>> torch% { echo BG: $RANDOM; sleep 30; } &
>> [1] 7442
>> BG: 12801
>> torch% bindkey "^M" _accept_and_quit
>> torch% { echo Here: $RANDOM; sleep 10 }
>> _accept_and_quit:5: you have running jobs.
>> torch% { echo Here: $RANDOM; sleep 10 }
>> torch% Here: 29846
>> echo not exited
>> torch%
>> zsh: warning: 1 jobs SIGHUPed
>>
>>
>> It's the same effect as this:
>>
>> torch% { sleep 30 } &
>> [1] 7457
>> torch% exit
>> zsh: you have running jobs.
>> torch% exit
>> zsh: warning: 1 jobs SIGHUPed
>>
>> The difference is that the "you have running jobs" message is suppressed
>> when exit is called from a zle widget.
>>
>> If Mikael adds "unsetopt checkjobs" he should get the effect he wants.
>> He might also want "setopt nohup" to prevent the death of whatever it
>> is that's keeping the shell alive.
>
> A good theory, but
> zshrun ~> echo $options[checkjobs]
> off
> I've always had that option turned off.
>
> Also, since the command is run with &| then surely there are no jobs either way?
>
>> The part about "commands are randomly ran two or three times" does not
>> happen for me -- though I don't know exactly what it means. Does it
>> mean you can invoke _accept_and_quit two or three times, or does it
>> mean that running _accept_and_quit once mysteriously launches the same
>> job two or three times?
>
> It seems to be run once in the background by the widget, and then
> another one in the foreground that I can ctrl-c out of. I only press
> enter the one time.
If I comment out the exit in my widget, then the command is only run
once, and the commandline stays as it is.
If I put set -x at the head of the function, I get this output when
pressing enter with also the zsh -c line commented out first:
+_accept_and_quit:2> local -a buf
+_accept_and_quit:3> buf=( urxvt )
+_accept_and_quit:4> which urxvt
+_accept_and_quit:6> exit
when the last line is printed, urxvt is run in the foreground. After
exiting that terminal, our zsh exits.
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author