From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13952 invoked by alias); 15 Dec 2009 10:02:49 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 27520 Received: (qmail 12491 invoked from network); 15 Dec 2009 10:02:37 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=AWL,BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.2.5 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) Message-Id: <200912151002.nBFA2Ve3029420@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-workers@zsh.org Subject: Re: What's the last command in prompt expansion? In-reply-to: References: Comments: In-reply-to =?UTF-8?Q?J=C3=B6rg?= Sommer message dated "Mon, 14 Dec 2009 22:53:33 +0000." Date: Tue, 15 Dec 2009 10:02:31 +0000 From: Peter Stephenson X-OriginalArrivalTime: 15 Dec 2009 10:02:31.0295 (UTC) FILETIME=[B74218F0:01CA7D6D] Content-Type: text/plain MIME-Version: 1.0 X-Scanned-By: MailControl A-09-22-10 (www.mailcontrol.com) on 10.68.0.134 =?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 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