Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Using the same completion function for various commands
- X-seq: zsh-users 15621
- From: Peter Stephenson <Peter.Stephenson@xxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Using the same completion function for various commands
- Date: Mon, 6 Dec 2010 16:10:20 +0000
- In-reply-to: <AANLkTin8Kn88NXsK4V4Toos0-ZB2hj4RvhX5QxLarq1N@xxxxxxxxxxxxxx>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- Organization: Cambridge Silicon Radio
- References: <201012061512.21791.mrichter@xxxxxxxxxxxxxxxxxxxxxxxx> <AANLkTimY=rEETn1uOdkDJ33kGE=YUDAvevsBvvvMU7YL@xxxxxxxxxxxxxx> <AANLkTim1Ac1-VOkRQ1NXn_qL6-EV06bagVkK7y_UThwB@xxxxxxxxxxxxxx> <AANLkTin+NCoBRzx90fo+s0z7urCCoTA6T3cXTYdt_VD2@xxxxxxxxxxxxxx> <20101206151124.389fd287@xxxxxxxxxxxxxxxxxxxxxxxxx> <AANLkTin8Kn88NXsK4V4Toos0-ZB2hj4RvhX5QxLarq1N@xxxxxxxxxxxxxx>
On Mon, 6 Dec 2010 16:18:47 +0100
Mikael Magnusson <mikachu@xxxxxxxxx> 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 <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