Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: What's the last command in prompt expansion?
- X-seq: zsh-workers 27520
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: What's the last command in prompt expansion?
- Date: Tue, 15 Dec 2009 10:02:31 +0000
- In-reply-to: <slrnhidgfb.2pm.joerg@xxxxxxxxxxxx>
- 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: <slrnhidgfb.2pm.joerg@xxxxxxxxxxxx>
=?UTF-8?Q?J=C3=B6rg?= Sommer wrote:
> what should be the expansion of %? in the prompt, the return code of the
> last command run at the prompt or the return code of the last command run
> by zsh?
Neither, necessarily, it's more complicated than that. Most
encapsulated commands---precmd, chpwd etc. etc., plus anything in
zle---save and restore the status. However, anything considered by the
shell to be run as part of the main execution thread (a phrase I
deliberately haven't attempted to define in detail) will set the status
directly.
> I've a function triggered via TRAPALARM that modifies PS1, by resetting
> its value and running zle reset-prompt. After the first time this
> function was executed the return value isn't the one of the last command,
> e.g. it's not 1 after executing false.
>
> Do I have to save the return value and put the value into PS1?
Traps don't save and restore the status. This is deliberate, they are
supposed to be able to return a status to the surrounding environment.
Saving the status in TRAPALRM might be good enough for your purposes.
TRAPALRM() {
integer stat=$?
# ....
return $stat
}
However, that might have side effects in some cases, since return values
from traps are special; I'd have to look in more detail to decide if
this is important with TRAPALRM, it may not be. Also, since TRAPALRM is
usually executed at the command prompt maybe this isn't important. (I
presume you're trying to trap keyboard inactivity so there isn't a
simple way of doing this with, say, the periodic function.)
--
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