Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: _file_systems & Re: zstyle for _arguments feature request
- X-seq: zsh-workers 16410
- From: Sven Wischnowsky <wischnow@xxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: PATCH: _file_systems & Re: zstyle for _arguments feature request
- Date: Mon, 7 Jan 2002 15:47:46 +0100
- In-reply-to: <20011211152415.85017.qmail@xxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20011211152415.85017.qmail@xxxxxxxxxxxxxxxxxxxxxx>
Oliver Kiddle wrote:
> ...
>
> Another method that might make things a little easier for user's unsure
> about writing whole functions would be to allow simple one line
> completions to be defined thusly:
>
> compdef '_files -g "*.c"' lcc
> compdef 'compadd one two three' count
>
> It might be generally useful to allow arguments in the values of
> _comps anyway.
And here is a patch for this. Not very nice, because we use $_comps in
several places and I've just added `eval's there. Probably should be
put into a separate function, but somehow it looks to small and simple
for that.
This, too, I'm not going to commit until I get replies.
Bye
Sven
diff -ur ../oz/Completion/Base/Completer/_complete ./Completion/Base/Completer/_complete
--- ../oz/Completion/Base/Completer/_complete Sun Dec 23 17:51:42 2001
+++ ./Completion/Base/Completer/_complete Sun Dec 23 18:01:15 2001
@@ -85,7 +85,7 @@
ccarray[3]="$compcontext"
comp="$_comps[$compcontext]"
- [[ -z "$comp" ]] || "$comp"
+ [[ -z "$comp" ]] || eval "$comp"
fi
return
@@ -97,7 +97,7 @@
if [[ ! -z "$comp" ]]; then
service="${_services[-first-]:--first-}"
ccarray[3]=-first-
- "$comp" && ret=0
+ eval "$comp" && ret=0
if [[ "$_compskip" = all ]]; then
_compskip=
return ret
@@ -136,7 +136,7 @@
comp="$_comps[-default-]"
fi
[[ -z "$comp" ]] ||
- service="${_services[-default-]:--default-}" && "$comp" && ret=0
+ service="${_services[-default-]:--default-}" && eval "$comp" && ret=0
fi
_compskip=
diff -ur ../oz/Completion/Base/Core/_normal ./Completion/Base/Core/_normal
--- ../oz/Completion/Base/Core/_normal Sun Dec 23 17:51:42 2001
+++ ./Completion/Base/Core/_normal Sun Dec 23 17:59:46 2001
@@ -19,7 +19,7 @@
curcontext="${curcontext%:*:*}:-command-:"
comp="$_comps[-command-]"
- [[ -z "$comp" ]] || "$comp" && ret=0
+ [[ -z "$comp" ]] || eval "$comp" && ret=0
return ret
else
@@ -86,7 +86,7 @@
if [[ -n "$comp" ]]; then
_compskip=patterns
- "$comp" && ret=0
+ eval "$comp" && ret=0
[[ "$_compskip" = (all|*patterns*) ]] && return ret
elif [[ "$_compskip" != *default* ]]; then
name=-default-
@@ -121,7 +121,7 @@
fi
[[ "$name" = -default- && -n "$comp" && "$_compskip" != (all|*default*) ]] &&
- service="${_services[-default-]:--default-}" && "$comp" && ret=0
+ service="${_services[-default-]:--default-}" && eval "$comp" && ret=0
_compskip=''
diff -ur ../oz/Completion/Base/Utility/_contexts ./Completion/Base/Utility/_contexts
--- ../oz/Completion/Base/Utility/_contexts Sun Dec 23 17:51:42 2001
+++ ./Completion/Base/Utility/_contexts Sun Dec 23 18:01:38 2001
@@ -11,7 +11,7 @@
for i; do
tmp="$_comps[$i]"
- [[ -z "$tmp" ]] || service="${_services[$i]:-$i}" && "$tmp" && ret=0
+ [[ -z "$tmp" ]] || service="${_services[$i]:-$i}" && eval "$tmp" && ret=0
done
return ret
diff -ur ../oz/Completion/Unix/Command/_su ./Completion/Unix/Command/_su
--- ../oz/Completion/Unix/Command/_su Sun Dec 23 17:51:42 2001
+++ ./Completion/Unix/Command/_su Sun Dec 23 18:02:09 2001
@@ -18,5 +18,5 @@
compset -n $base
for name in $shell $shell:t -default-; do
comp="$_comps[$name]"
- [[ -n "$comp" ]] && "$comp" && return
+ [[ -n "$comp" ]] && eval "$comp" && return
done
diff -ur ../oz/Doc/Zsh/compsys.yo ./Doc/Zsh/compsys.yo
--- ../oz/Doc/Zsh/compsys.yo Sun Dec 23 17:51:42 2001
+++ ./Doc/Zsh/compsys.yo Sun Dec 23 18:26:46 2001
@@ -270,6 +270,15 @@
`var(cmd)tt(=)var(service)'. This kind of use makes the arguments of
the var(cmd)s be completed as those for the var(services).
+In the first case and the following cases the var(function) may actually
+be a string containing any shell code and that string will be executed
+via the tt(eval) builtin command. This allows to easily define completions
+for commands that need to call one of the completion functions with
+arguments. For example to make files ending in `tt(.h)' be completed as
+arguments to the command tt(foo), one would use:
+
+example(compdef '_files -g "*.h"' foo)
+
If the
tt(-n) option is given, any existing completion behaviour for particular
contexts or commands will not be altered. These definitions can be deleted
--
Sven Wischnowsky wischnow@xxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author