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

Re: zle clear-screen, exit status



On Tue, 19 Oct 2010 11:32:58 -0400
Brian Lewis <brian@xxxxxxxx> wrote:
> My prompt displays $?, the program exit status. When I hit Ctrl-L, I'd
> like $? to be set to 0 somehow before the prompt is redisplayed.
> 
> I can't figure out how to do it. It is as if $? is saved before my
> widget is called, and restored after.

Yes, that's how it works.  The status returned from widgets is for use by
ZLE; it is not related to the status of the sequence of commands you are
running on the command line, which doesn't care what sequence of
commands was executed to read in the command line.  Generally speaking,
functions only return the value to their immediate environment and that
propagates up as appropriate --- there's no automatic link between
return statuses of functions and the top level of execution, it depends
on context.

We take care to try to ensure that even stray statuses from hook
functions don't overwrite the status in the main command sequence, so
the zle-line-finish widget doesn't help you, either.

You'd need to trick the shell into thinking it was in the top-level
shell execution environment or executing code outside the usual widget
sandbox.  I can't offhand think of a way of doing that within zle.  Even
when executing an exit trap in a shell function the status is tidied up
afterwards.

-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom



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