From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14872 invoked from network); 25 Apr 2005 13:37:01 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 25 Apr 2005 13:37:01 -0000 Received: (qmail 98717 invoked from network); 25 Apr 2005 13:36:54 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 25 Apr 2005 13:36:54 -0000 Received: (qmail 29126 invoked by alias); 25 Apr 2005 13:36:52 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 21189 Received: (qmail 29115 invoked from network); 25 Apr 2005 13:36:51 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 25 Apr 2005 13:36:51 -0000 Received: (qmail 98429 invoked from network); 25 Apr 2005 13:36:51 -0000 Received: from mailhost1.csr.com (HELO MAILSWEEPER01.csr.com) (81.105.217.43) by a.mx.sunsite.dk with SMTP; 25 Apr 2005 13:36:43 -0000 Received: from exchange03.csr.com (unverified [10.100.137.60]) by MAILSWEEPER01.csr.com (Content Technologies SMTPRS 4.3.12) with ESMTP id for ; Mon, 25 Apr 2005 14:35:00 +0100 Received: from news01.csr.com ([10.103.143.38]) by exchange03.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Mon, 25 Apr 2005 14:37:08 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.13.1/8.12.11) with ESMTP id j3PDafon025209 for ; Mon, 25 Apr 2005 14:36:41 +0100 Received: from csr.com (pws@localhost) by news01.csr.com (8.13.1/8.13.1/Submit) with ESMTP id j3PDafGF025206 for ; Mon, 25 Apr 2005 14:36:41 +0100 Message-Id: <200504251336.j3PDafGF025206@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: Zsh hackers list Subject: Re: Updated _acroread completer In-reply-to: <20050425130002.GA3137@fox> References: <20050414134703.GA7862@s> <20050415111158.GA1709@s> <7344.1114415007@trentino.groupinfra.com> <20050425084156.GA483@fox> <200504250939.j3P9dqih005645@news01.csr.com> <20050425130002.GA3137@fox> Date: Mon, 25 Apr 2005 14:36:40 +0100 From: Peter Stephenson X-OriginalArrivalTime: 25 Apr 2005 13:37:08.0567 (UTC) FILETIME=[E0879E70:01C5499B] X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.6 required=6.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.6 Haakon Riiser wrote: > By the way, it uses "sed -n 's/^ver=//p' FILE" to extract the > version. Is it preferable to use zsh's own string functions to > do this? The code tends to become quite hard to read, and I usually > need to spend much more time writing it than when I use sed or awk. As you need to scan an entire file for this, sed is probably as good as anything. However, you'll see things as bad as the following, and even worse, inside the completion code. The zsh version of: local ver=$(sed -n 's/^ver=//p' $commands[$words[1]] 2>/dev/null) would be (with EXTENDED_GLOB set): ver=${${${(f)"$(<$commands[$words[1]])"}:#^ver=*}##ver=} which isn't fantastically easy to understand: "$(<$commands[$words[1]])" Output the contents of the file given by $commands[$words[1]] as a single string. ${(f)"$(<$commands[$words[1]])"} Split the result into an array of lines. (This forces array context despite the scalar assignment.) ${${(f)"$(<$commands[$words[1]])"}:#^ver=*} Remove all elements of the resulting array (lines of the file) that match ^ver=*, i.e. all lines except those that match ver=*. ${${${(f)"$(<$commands[$words[1]])"}:#^ver=*}##ver=} Remove the ver= from the head of the result. At this point it will be treated as a scalar for the assignment, but that's OK if there's just the one match. There's no equivalent of sed's p (do the substitution and output the result if the substitution succeeded), which is why we need to match on the ver= twice. But there are still spare letters for flags... -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. **********************************************************************