From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17046 invoked from network); 2 Jan 2002 16:25:38 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 2 Jan 2002 16:25:38 -0000 Received: (qmail 8959 invoked by alias); 2 Jan 2002 16:25:24 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 4560 Received: (qmail 8947 invoked from network); 2 Jan 2002 16:25:23 -0000 X-VirusChecked: Checked X-Authentication-Warning: iris.logica.co.uk: Host kiddleo@rambo.logica.co.uk [158.234.33.58] claimed to be yahoo.co.uk Sender: kiddleo@iris.logica.co.uk Message-ID: <3C333453.9CB23105@yahoo.co.uk> Date: Wed, 02 Jan 2002 16:24:52 +0000 From: Oliver Kiddle X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.4.16-686-smp i686) X-Accept-Language: en MIME-Version: 1.0 To: Matt Armstrong CC: zsh-users@sunsite.dk Subject: Re: I wonder if this can be improved a bit References: <87ellbxkek.fsf@squeaker.lickey.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Matt Armstrong wrote: > > I'm implementing a completion system for Perforce's > a=( ${(f)"$(p4 -s help commands 2>&1)"} ) > a=( ${(M)a:#info: *} ) > a=( ${a/(#b)info: #([a-z0-9]##) */$match[1]} ) you can nest those substitutions if you want, not that it makes much difference. > typeset -A _p4_cmds > _p4_cmds=() > for i in $a; do > _p4_cmds[$a]="" should that not be _p4_cmds[$i]="" > So now _p4_cmds is an associative array of available sub commands. > Here I have annotated questions about this code. > > # This requires EXTENDED_GLOB to be set > setopt extendedglob > > Can I depend on the completion widgets setting EXTENDED_GLOB for me? Yes. The _comp_options array contains the list of options set for completion. > > local a > a=( ${(f)"$(p4 -s help commands 2>&1)"} ) > > I will eventually change this to the more correct > "$(_call_program commands p4 -s help commands) ". I'd use $words[1] instead of p4 so that it will work if p4 is not in the path but is specified with its location. > a=( ${(M)a:#info: *} ) > > ^^^ > The whitespace there is a space followed by a tab character. Is there > any more readable way to include a tab character? A \t escape sequence? $'\t' In some circumstances, you may also be able to make use of [[:blank:]]. > Is there a simple way to turn an array (a b c) into (a "" b "" c "")? > Then I could assign _p4_cmds in one statement and dump the loop. See my -workers post on this question. Oliver This email has been scanned for all viruses by the MessageLabs SkyScan service. For more information on a pro-active anti-virus service working around the clock, around the globe visit http://www.messagelabs.com/