From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21835 invoked from network); 14 Aug 2004 16:11:32 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 14 Aug 2004 16:11:32 -0000 Received: (qmail 97918 invoked from network); 14 Aug 2004 16:11:26 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 14 Aug 2004 16:11:26 -0000 Received: (qmail 18142 invoked by alias); 14 Aug 2004 16:09:32 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7843 Received: (qmail 18127 invoked from network); 14 Aug 2004 16:09:32 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by 130.225.247.90 with SMTP; 14 Aug 2004 16:09:32 -0000 Received: (qmail 92725 invoked from network); 14 Aug 2004 16:07:34 -0000 Received: from sccimhc92.asp.att.net (63.240.76.166) by a.mx.sunsite.dk with SMTP; 14 Aug 2004 16:07:32 -0000 Received: from louisville.edu (12-220-223-80.client.insightbb.com[12.220.223.80]) by sccimhc92.asp.att.net (sccimhc92) with SMTP id <20040814160730i920091aaue>; Sat, 14 Aug 2004 16:07:30 +0000 Date: Sat, 14 Aug 2004 12:07:28 -0400 Subject: Re: Execute a Command in PS1 w/o Disturbing Previous Return Value? Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v553) From: Aaron Davies To: zsh-users@sunsite.dk Content-Transfer-Encoding: 7bit In-Reply-To: Message-Id: <0A5C860F-EE0C-11D8-83BE-000502631FBD@louisville.edu> X-Mailer: Apple Mail (2.553) X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: * X-Spam-Status: No, hits=1.6 required=6.0 tests=BAYES_30,FROM_ENDS_IN_NUMS, RCVD_IN_SORBS autolearn=no version=2.63 X-Spam-Hits: 1.6 On Friday, August 13, 2004, at 01:32 PM, Bart Schaefer wrote: > On Thu, 12 Aug 2004, Aaron Davies wrote: > >> I'm trying to write a prompt that will do two things: include a file >> frequently re-downloaded from the web, and indicate the return status >> of >> the previous command. The problem is, if I cat out the file, it >> returns >> 0, overwriting the return status read by the %(0?%) directive > > This should probably be considered a bug. I dunno, I can see where someone might want a prompt so complicated it needed internal error-handling based on return value of executed commands (cat foo || cat bar, etc.). Would "fixing" this prevent that? >> What can I do about this? > > In addition to Philippe's suggestion of using precmd so that $? is > saved > and restored for you by the shell -- which is what should be happening > during command substitutions in prompt expansion, but isn't -- a simple > alternative is to use $(<...) instead of `cat ...`. > > You can also use $'...' instead of `echo '...'` > > export PS1='$( $'%{\e[1;32m%}:)%{\e[0m%}.%{\e[1;31m%}:(%{\e[0m%}'") %# " Thank you, that works perfectly! -- __ __ / ) / ) /--/ __. .__ ______ / / __. , __o _ _ / (_(_/|_/ (_(_) / (_ (__/_(_/|_\/ <__