Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: namespace completions ?
- X-seq: zsh-users 18455
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Marc Chantreux <khatar@xxxxxxxxx>
- Subject: Re: namespace completions ?
- Date: Sat, 15 Feb 2014 00:55:00 +0100
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s1024; t=1392422101; bh=4mVrdgHnQ9XacLkbhjschFiNS4bL6H0kfSZ7aNz039o=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:X-Rocket-Received:Received:cc:In-reply-to:From:References:To:Subject:MIME-Version:Content-Type:Content-ID:Date:Message-ID; b=OGB1ovSBxdRHkQK+7EqQIKTUo1WvEXpiEId9A9okBxg3emPXfCkx+qzZDafBSwLM3g46R6fRe0lVrhSQVMaW7T/kbGyR/f6gmz5hFa/Qu0z/g4l5uJbuatdTUjmJAac25C5Xj50u6SE32JevlpClcZGuNJEGDvPvQkXGqs8Hwfw=
- In-reply-to: <20140213100333.GA24676@ramirez.u-strasbg.fr>
- 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
- References: <20140213100333.GA24676@ramirez.u-strasbg.fr>
Marc Chantreux wrote:
>
> month later, we're happy users of the 'uze' convention:
> https://github.com/eiro/uze. but we want more! we want completion:
It's a pity that isn't using function autoloading. It had never occurred
to me before but it apparently works to autoload functions with slashes
in their names and have them picked up out of subdirectories of your
function path.
> saying https://github.com/eiro/uze is set and ready, i would like to
> write this from the CLI:
>
> mc@xxxxxxxxxxxx> a=unistra/annuaire
> mc@xxxxxxxxxxxx> . uze/$a
> mc@xxxxxxxxxxxx> $a/<tab>
So basically, you want completion of shell functions to handle the
beginning of the function being a variable reference in much the same
way as is done for filename completion. By copying parts of _path_files
to _functions, this can be done by modifying _functions as in the patch
below.
I'm not sure if it makes sense to commit this or some variant of it. Any
thoughts? Having borrowed from _path_files, it relies on / to mark the
end of the variable expression.
Oliver
diff --git a/Completion/Zsh/Type/_command_names b/Completion/Zsh/Type/_command_names
index d9fc62d..31cebb0 100644
--- a/Completion/Zsh/Type/_command_names
+++ b/Completion/Zsh/Type/_command_names
@@ -8,10 +8,6 @@ local args defs ffilt
zstyle -t ":completion:${curcontext}:commands" rehash && rehash
-zstyle -t ":completion:${curcontext}:functions" prefix-needed && \
- [[ $PREFIX != [_.]* ]] && \
- ffilt='[(I)[^_.]*]'
-
defs=(
'commands:external command:_path_commands'
)
@@ -28,7 +24,7 @@ else
defs=( "$defs[@]"
'builtins:builtin command:compadd -Qk builtins'
- "functions:shell function:compadd -k 'functions$ffilt'"
+ "functions:shell function:_functions"
'aliases:alias:compadd -Qk aliases'
'suffix-aliases:suffix alias:_suffix_alias_files'
'reserved-words:reserved word:compadd -Qk reswords'
diff --git a/Completion/Zsh/Type/_functions b/Completion/Zsh/Type/_functions
index 4d33669..0f4b5c6 100644
--- a/Completion/Zsh/Type/_functions
+++ b/Completion/Zsh/Type/_functions
@@ -1,9 +1,24 @@
#compdef unfunction
-local expl ffilt
+local expl funcs
+local ffilt=functions
zstyle -t ":completion:${curcontext}:functions" prefix-needed && \
[[ $PREFIX != [_.]* ]] && \
- ffilt='[(I)[^_.]*]'
+ ffilt+='[(I)[^_.]*]'
-_wanted functions expl 'shell function' compadd -k "$@" - "functions$ffilt"
+funcs=( ${(kP)ffilt} )
+if [[ "$PREFIX" = \$*/* && "$compstate[quote]" != \' ]]; then
+ local realstr
+ local linestr="${(M)PREFIX##*\$[^/]##/}"
+ function {
+ # do not treat an unset parameter expansion as the empty string
+ setopt localoptions nounset
+ eval 'realstr=${(e)~linestr}' 2>/dev/null
+ }
+ [[ -z "$realstr" || "$realstr" = "$linestr" ]] && return 1
+ funcs=( ${${(M)funcs:#$realstr*}##$realstr} )
+ compset -P $linestr
+fi
+
+_wanted functions expl 'shell function' compadd -a "$@" - funcs
Messages sorted by:
Reverse Date,
Date,
Thread,
Author