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 >