From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18327 invoked from network); 31 Dec 2001 19:24:57 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 31 Dec 2001 19:24:57 -0000 Received: (qmail 16463 invoked by alias); 31 Dec 2001 19:24:46 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 4558 Received: (qmail 16449 invoked from network); 31 Dec 2001 19:24:46 -0000 To: zsh-users@sunsite.dk Subject: I wonder if this can be improved a bit Date: Mon, 31 Dec 2001 12:24:35 -0700 Message-ID: <87ellbxkek.fsf@squeaker.lickey.com> User-Agent: Gnus/5.090004 (Oort Gnus v0.04) Emacs/21.1 (i386-debian-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii From: "Matt Armstrong" X-Delivery-Agent: TMDA/0.42+ (Python 2.1.1; linux-i686) X-Virus-Scanned: by AMaViS snapshot-20010714 I'm implementing a completion system for Perforce's () p4 command. Like CVS, the p4 command takes sub-commands (p4 add, p4 submit, etc.). The p4 command prints out the list of available sub-commands with "p4 -s help commands". I have this bit of code that'll eventually go into my _p4 completion system. But I wonder if it can be improved. # This requires EXTENDED_GLOB to be set setopt extendedglob local a a=( ${(f)"$(p4 -s help commands 2>&1)"} ) a=( ${(M)a:#info: *} ) a=( ${a/(#b)info: #([a-z0-9]##) */$match[1]} ) typeset -A _p4_cmds _p4_cmds=() for i in $a; do _p4_cmds[$a]="" done 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? 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) ". 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? a=( ${a/(#b)info: #([a-z0-9]##) */$match[1]} ) typeset -A _p4_cmds for i in $a; do _p4_cmds[$a]="" done 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. -- matt