From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14083 invoked by alias); 6 Dec 2010 16:10:32 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 15621 Received: (qmail 5665 invoked from network); 6 Dec 2010 16:10:30 -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,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) Date: Mon, 6 Dec 2010 16:10:20 +0000 From: Peter Stephenson To: Zsh Users Subject: Re: Using the same completion function for various commands Message-ID: <20101206161020.693f3f4a@pwslap01u.europe.root.pri> In-Reply-To: References: <201012061512.21791.mrichter@theory.phy.tu-dresden.de> <20101206151124.389fd287@pwslap01u.europe.root.pri> Organization: Cambridge Silicon Radio X-Mailer: Claws Mail 3.7.6 (GTK+ 2.20.1; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 06 Dec 2010 16:10:21.0087 (UTC) FILETIME=[14F01AF0:01CB9560] X-Scanned-By: MailControl A_10_80_00 (www.mailcontrol.com) on 10.71.0.122 On Mon, 6 Dec 2010 16:18:47 +0100 Mikael Magnusson wrote: > Ah, er, right. But. Is there any way to combine -p and saying foo=du ? > When I tried compdef _du -p 'foo_*=du' nothing happened. The current syntax isn't really powerful enough for that. The "foo_*=du" gets stored in _patcomps and then gets compared against the word on the command line. You'd need to put foo_* in the key and squirrel the "=du" away somewhere else. You could do it by (gasp) hacking the value, for example. (I'm surprised we don't already sanitise the option settings within compdef, seeing as you can call it from anywhere. I suppose we've got away with it because most people just have it running implicitly from within compinit.) Index: Completion/compinit =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/compinit,v retrieving revision 1.25 diff -p -u -r1.25 compinit --- Completion/compinit 8 Feb 2010 11:53:35 -0000 1.25 +++ Completion/compinit 6 Dec 2010 16:06:47 -0000 @@ -230,6 +230,10 @@ comppostfuncs=() compdef() { local opt autol type func delete new i ret=0 cmd svc + local -a match mbegin mend + + emulate -L zsh + setopt extendedglob # Get the options. @@ -364,10 +368,18 @@ compdef() { else case "$type" in pattern) - _patcomps[$1]="$func" + if [[ $1 = (#b)(*)=(*) ]]; then + _patcomps[$match[1]]="=$match[2]=$func" + else + _patcomps[$1]="$func" + fi ;; postpattern) - _postpatcomps[$1]="$func" + if [[ $1 = (#b)(*)=(*) ]]; then + _postpatcomps[$match[1]]="=$match[2]=$func" + else + _postpatcomps[$1]="$func" + fi ;; *) if [[ "$1" = *\=* ]]; then Index: Completion/Base/Core/_dispatch =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Base/Core/_dispatch,v retrieving revision 1.4 diff -p -u -r1.4 _dispatch --- Completion/Base/Core/_dispatch 3 Jun 2004 15:14:59 -0000 1.4 +++ Completion/Base/Core/_dispatch 6 Dec 2010 16:06:47 -0000 @@ -2,6 +2,7 @@ local comp pat val name i ret=1 _compskip="$_compskip" local curcontext="$curcontext" service str noskip +local -a match mbegin mend # If we get the option `-s', we don't reset `_compskip'. @@ -24,6 +25,10 @@ if [[ "$_compskip" != (all|*patterns*) ] [[ -n "$str" ]] || continue service="${_services[$str]:-$str}" for i in "${(@)_patcomps[(K)$str]}"; do + if [[ $i = (#b)"="([^=]#)"="(*) ]]; then + service=$match[1] + i=$match[2] + fi eval "$i" && ret=0 if [[ "$_compskip" = *patterns* ]]; then break -- 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