From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22811 invoked from network); 1 Apr 2004 17:17:50 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 1 Apr 2004 17:17:50 -0000 Received: (qmail 14084 invoked by alias); 1 Apr 2004 17:17:25 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7309 Received: (qmail 14048 invoked from network); 1 Apr 2004 17:17:24 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 1 Apr 2004 17:17:24 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [130.225.247.86] by sunsite.dk (MessageWall 1.0.8) with SMTP; 1 Apr 2004 17:17:24 -0000 Received: (qmail 27403 invoked from network); 1 Apr 2004 17:17:24 -0000 Received: from madrid10.amenworld.com (62.193.203.32) by a.mx.sunsite.dk with SMTP; 1 Apr 2004 17:17:22 -0000 Received: from DervishD.pleyades.net (212.Red-80-35-44.pooles.rima-tde.net [80.35.44.212]) by madrid10.amenworld.com (8.10.2/8.10.2) with ESMTP id i31HHJs08870 for ; Thu, 1 Apr 2004 19:17:19 +0200 Received: from raul@pleyades.net by DervishD.pleyades.net with local (Exim MTA 2.05) id <1B95az-0006kw-00>; Thu, 1 Apr 2004 19:03:13 +0200 Date: Thu, 1 Apr 2004 19:03:13 +0200 From: DervishD To: Zsh Users Subject: Honoring a command Message-ID: <20040401170312.GA25965@DervishD> Mail-Followup-To: Zsh Users Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.4.2.1i Organization: Pleyades 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 Hi all :) A couple of weeks ago one of the list members asked about justifying some script output, and I decided to er.. inspire from (that is, steal) that idea and I want to modify some scripts I have from something like: Printing file whatever.ps... done. to something like: Printing file whatever.ps [ok] justified to the screen width. This is not a problem since thanks to this list I know how to do the justification, but the question is that I want to modify code like this: print -n "Doing whatever command..." >&2 whatever.command 2> /dev/null || { print " error! Message" >&2; return 1; } print " done." >&2 to this: verbosely_do "Doing whatever command" whatever.command \ || { print "Message" >&2; return 1;} The function 'verbosely_do' is pretty easy: function verbosely_do() { emulate -L zsh print -n ${(r:(($WIDTH)):)1} >&2 $* || { print "[!]" >&2 return 1 } print "[*]" >&2 return 0 } $WIDTH is defined elsewhere or can be even a fixed number, and the symbols may have colors, etc... The important point is that the function prettyprints some messages and run the commands. Please, pretend that you don't notice that bare '$*' that may expand to an empty string ;)) That will corrected later. The problem I see is: what will happen if the command has redirections, metacharacters, quotes, variable references, etc.? Will it be run by 'verbosely_do' correctly, that is, exactly in the same way as it was run in the code without 'verbosely_do', or should I preprocess it in some way? As an example: verbosely_do "Command" chown -R `id -un`:`id -gn` "$SOURCES" Although it may be any command that will run correctly given itself alone in any script. Thanks a lot and please excuse me for such weird question O:) Raúl Núñez de Arenas Coronado -- Linux Registered User 88736 http://www.pleyades.net & http://raul.pleyades.net/