From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18251 invoked from network); 5 Apr 2004 01:09:50 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 5 Apr 2004 01:09:50 -0000 Received: (qmail 18190 invoked by alias); 5 Apr 2004 01:09:36 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7325 Received: (qmail 18161 invoked from network); 5 Apr 2004 01:09:36 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 5 Apr 2004 01:09:36 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [130.225.247.86] by sunsite.dk (MessageWall 1.0.8) with SMTP; 5 Apr 2004 1:9:36 -0000 Received: (qmail 1524 invoked from network); 5 Apr 2004 01:09:35 -0000 Received: from wbar3.sjo1-4-11-009-147.sjo1.dsl-verizon.net (HELO candle.brasslantern.com) (4.11.9.147) by a.mx.sunsite.dk with SMTP; 5 Apr 2004 01:09:33 -0000 Received: (from schaefer@localhost) by candle.brasslantern.com (8.11.6/8.11.6) id i3519Wh22508 for zsh-users@sunsite.dk; Sun, 4 Apr 2004 18:09:32 -0700 X-Authentication-Warning: candle.brasslantern.com: schaefer set sender to schaefer@closedmail.com using -f From: Bart Schaefer Message-Id: <1040405010932.ZM22507@candle.brasslantern.com> Date: Mon, 5 Apr 2004 01:09:32 +0000 In-Reply-To: <20040404111615.GI27014@DervishD> Comments: In reply to DervishD "Re: Honoring a command" (Apr 4, 1:16pm) References: <20040401170312.GA25965@DervishD> <1040403214330.ZM15892@candle.brasslantern.com> <20040404111615.GI27014@DervishD> X-Mailer: Z-Mail (5.0.0 30July97) To: Zsh Users Subject: Re: Honoring a command MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: **** X-Spam-Status: No, hits=4.7 required=6.0 tests=RCVD_IN_DYNABLOCK, RCVD_IN_NJABL,RCVD_IN_NJABL_DIALUP,RCVD_IN_SORBS autolearn=no version=2.63 X-Spam-Hits: 4.7 On Apr 4, 1:16pm, DervishD wrote: } } The number of beers I owe you is growing dangerously ;) Especially considering that I rarely drink beer. Send me a six-pack of some unusual Spanish soft drink, or something. ;-} } alias scriptinit=$'emulate -L zsh ; trap \'return $LINENO\' ZERR' An interesting tidbit I just noticed -- if you read the script with the "source" or "." commands, $LINENO is reset to 1 when the trap runs, so you don't get as useful a return value. } The problem is that it doesn't work with the above usage of } verbosely_watch, because the trap is never run due to the OR list. I } must replace: } } { whatever.command 2> /dev/null || print "Error message"} } } by: } } { whatever.command 2> /dev/null || print "Error message";false} Actually that won't work either, because that _always_ executes "false". I think you meant { whatever.command 2> /dev/null || { print "Error message";false } } } but then 'verbosely_watch' has no purpose at all! You could write another little function: verbosely_fail() { local ret=$? [[ -p /dev/fd/1 ]] && print "$*" return ret } Now this works: { whatever.command || verbosely_fail "Error message" } 2>/dev/null | verbosely_watch "Doing whatever" If you DON'T pipe to verbosely_watch, then verbosely_fail is silent and the ZERR trap returns the line number as $?. (Even if you do pipe it, the line number is stored in $pipestatus[1], which may be useful for other tricks.) } I think I'd better use 'scriptinit' only for muted } scripts and verbosely_watch for the rest, using TRAPZERR for the } error message. Is that a good idea? That would work as well, but it means the error message is the same for every command (unless you re-assign it somehow each time).