Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: bash compgen -W compatibility patch
- X-seq: zsh-workers 29144
- From: Rocky Bernstein <rocky@xxxxxxx>
- To: Peter Stephenson <Peter.Stephenson@xxxxxxx>
- Subject: Re: bash compgen -W compatibility patch
- Date: Tue, 3 May 2011 14:27:07 -0400
- Cc: zsh-workers@xxxxxxx
- 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=
- In-reply-to: <20110503154550.04b3fcef@pwslap01u.europe.root.pri>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <BANLkTik3WXLMge2bc9Oe48ZXtCT0aEGqZg@mail.gmail.com> <20110503154550.04b3fcef@pwslap01u.europe.root.pri>
- Sender: rocky.bernstein@xxxxxxxxx
On Tue, May 3, 2011 at 10:45 AM, Peter Stephenson
<Peter.Stephenson@xxxxxxx>wrote:
> On Tue, 3 May 2011 08:25:50 -0400
> Rocky Bernstein <rocky@xxxxxxx> 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 <pws@xxxxxxx> 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
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author