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

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



On Mon, May 18, 2015 at 2:14 PM, Peter Stephenson
<p.stephenson@xxxxxxxxxxx> wrote:
> On Mon, 18 May 2015 13:38:15 +0200
> Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>> This patch breaks my setup.
>>
>> # Some hooks into accept-line
>> if [[ -n "$ZSHRUN" ]]; then
>>   unsetopt correct
>>   function _accept_and_quit() {
>>   local -a buf
>>   buf=(${(z)BUFFER})
>>   if which $buf[1] >& /dev/null; then
>>     zsh -c "${BUFFER}" &|
>>     exit
>>   else
>>     zle -M "Command $buf[1] not found"
>>   fi
>>   }
>>   zle -N _accept_and_quit
>>   bindkey "^M" _accept_and_quit
>> fi
>>
>> With the patch, commands are randomly ran two or three times instead
>> of just once in the background. AFAIK there are no always blocks
>> involved in this part of my rc.
>
> Are you actually trying to exit from the main shell here?  It claims to
> be a hook into accept-line but it doesn't look to me like it is.

Yes, I have a slightly alternate codepath through my .zshrc triggered
by ZSHRUN being set in the env, used for a Win+r shortcut to run
simple commands in the background. The comment is probably more
accurate for the hook defined below that, used for the normal main
shell case.

> The key here is presumably sorting out what functions are running at
> what level, i.e. where the "exit" command is first run and where the
> shell actually exits (you could trying adding a message after "exit" to
> see if that gets run, though that probably won't help since "retflag" is
> likely to be set at that point).  In particular, what should happen is
> the code at the end of doshfunc() causes the shell to exit at the end of
> _accept_and_quit.  The simpler the case, the more likely
> the relationship is to come out.

I would have expected the shell to exit when encountering the "exit"
command, and run no further commands, no matter the circumstances.
Probably a naive viewpoint considering all I've seen. I've reverted
the patch locally for now, but I might investigate more later then.

-- 
Mikael Magnusson



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