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

Re: "{ } always { }" construct and return in called functions



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.

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?



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