From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18605 invoked from network); 13 Aug 2004 04:54:27 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 13 Aug 2004 04:54:27 -0000 Received: (qmail 51918 invoked from network); 13 Aug 2004 04:54:21 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 13 Aug 2004 04:54:21 -0000 Received: (qmail 19366 invoked by alias); 13 Aug 2004 04:53:09 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7821 Received: (qmail 19356 invoked from network); 13 Aug 2004 04:53:09 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by 130.225.247.90 with SMTP; 13 Aug 2004 04:53:09 -0000 Received: (qmail 48712 invoked from network); 13 Aug 2004 04:52:12 -0000 Received: from tantale.fifi.org (216.27.190.146) by a.mx.sunsite.dk with SMTP; 13 Aug 2004 04:52:11 -0000 Received: from ceramic.fifi.org (mail@ceramic.fifi.org [216.27.190.147]) by tantale.fifi.org (8.9.3p2/8.9.3/Debian 8.9.3-21) with ESMTP id VAA14143; Thu, 12 Aug 2004 21:52:06 -0700 Received: from phil by ceramic.fifi.org with local (Exim 4.22) id 1BvU2w-0007jj-1y; Thu, 12 Aug 2004 21:52:06 -0700 To: Aaron Davies Cc: zsh-users@sunsite.dk Subject: Re: Execute a Command in PS1 w/o Disturbing Previous Return Value? References: Mail-Copies-To: nobody From: Philippe Troin Date: 12 Aug 2004 21:52:06 -0700 In-Reply-To: Message-ID: <87y8kj1vyh.fsf@ceramic.fifi.org> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: Philippe Troin X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=0.0 required=6.0 tests=none autolearn=no version=2.63 X-Spam-Hits: 0.0 Aaron Davies writes: > 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, > and guaranteeing that I will always get a prompt indicating > success. What can I do about this? > > Here's the whole line. The breakdown is: current temperature, pwd, (if > last command successful, a green smiley, else a red frowny), prompt > char. > > export PS1='`cat /tmp/temperature`'" %m%~ %(0?."`echo > '%{\e[1;32m%}:)%{\e[0m%}'`"."`echo \ > '%{\e[1;31m%}:(%{\e[0m%}'`") %# " > > (/tmp/temperature is refreshed every five minutes by a cron job, in > case you were wondering.) What about: precmd() { local r=$? psvar=() psvar=("$(< /tmp/temperature)") (( $r )) && psvar=($psvar $r) } export PS1="$(print '%1v %m%~ %(2v,%{\e[1;31m%}:( [%2v]%{\e[0m%},%{\e[1;32m%}:%)%{\e[0m%}) %# ')" I prefer "setopt printexitvalue" myself... Phil.