From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1624 invoked by alias); 3 May 2011 18:27:16 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 29144 Received: (qmail 18813 invoked from network); 3 May 2011 18:27:13 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 74.125.82.43 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=emOmu7F4cqxu29vBVi1oWm2L0zUM0/RZqn8bFUXPcFM=; b=NSRTHzmdTr1NvP/i4r34BQWmQz5urCQBn2MRaRq0gOpJtPvxpsnIaANWhOBHTdfCGM pchmdJ1rTWLNp5U7ANuxudkn9PCp5yk2SauWriosh9hrcUu5TVXA6GKaWcOeXh6Lbwwr OLEBqk9+EqXObASkCmjosSrR9feY1oalCy0Kg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=XcPUwnZYk833GguH9xPpp5YYgXMPZFva62d6gJY9FTcm1942Po1/5oGvtPZ1z3x2uX 1KLn6fs1sXhx9vi8U8f2g4abwCa56ZHJigBWcLAl33Jtk2vmGsJl7klH9O+cGMKIZLll 4PfORInKxyWsaXdX9fLm3JHT5SwLdvnJUXfAo= MIME-Version: 1.0 Sender: rocky.bernstein@gmail.com In-Reply-To: <20110503154550.04b3fcef@pwslap01u.europe.root.pri> References: <20110503154550.04b3fcef@pwslap01u.europe.root.pri> Date: Tue, 3 May 2011 14:27:07 -0400 X-Google-Sender-Auth: S1elKb0UQ4ND-CTeD3_D9WksLR4 Message-ID: Subject: Re: bash compgen -W compatibility patch From: Rocky Bernstein To: Peter Stephenson Cc: zsh-workers@zsh.org Content-Type: multipart/alternative; boundary=e0cb4e43cd559c0cdf04a2634921 --e0cb4e43cd559c0cdf04a2634921 Content-Type: text/plain; charset=ISO-8859-1 On Tue, May 3, 2011 at 10:45 AM, Peter Stephenson wrote: > On Tue, 3 May 2011 08:25:50 -0400 > Rocky Bernstein wrote: > > For example simplicity, to match the beginning of a word, I used > > [[ $try =~ "^$find" ]] > > matching using == and substrings might be faster, not that I think > > speed is all that important here. Ditt ofo inlining a newly added > > _compgen_opt_words function; but I think that makes things uglier and > > harder to test. > > > >... > > > > +_compgen_opt_words() { > > + typeset -a words > > + eval "words=( $1 )" > > + local find > > + find=$2 > > + local try > > + find=${@[-1]} > > + for try in ${words[@]} ; do > > + if [[ $try =~ "^$find" ]] ; then > > + results+=( $try ) > > + fi > > + done > > + results=( "${(k)results[@]}" ) > > +} > > Thanks. It's actually possible to abbreviate this quite a lot, in ways > which are used widely in the completion code. Also, the eval looks a > bit hairy because $1 can contain anything, and I think it's good enough > to ensure that $1 is split into words and any pattern characters are > active, which can be done without an eval. > > _compgen_opt_words() { > typeset -a words > words=( ${~=1} ) > local find try > find=${@[-1]} > Probably simpler would be to use $2, i.e find=$2 I mistakenly had set find twice in the patch. results=(${(M)words[@]:#$find*}) > } > > seems to work, unless I'm missing some basic ingredient. If I'm not, > I'll commit this. > I've replaced my code in zshdb with the above and the tests run. No doubt if there's a problem there's a test file which can be expanded. Thanks for looking over and fixing. > > -- > Peter Stephenson Software Engineer > Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited > Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, > UK > > > Member of the CSR plc group of companies. CSR plc registered in England and > Wales, registered number 4187346, registered office Churchill House, > Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom > --e0cb4e43cd559c0cdf04a2634921--