[pve-devel] [PATCH common] Fix 1891: Add zsh tab completion script generator
Thomas Lamprecht
t.lamprecht at proxmox.com
Tue Feb 19 17:12:23 CET 2019
On 2/8/19 4:41 PM, Christian Ebner wrote:> Add zsh tab completion generator function to automatically generate the
> zsh scripts used for autocompletion.
> This uses the older zsh completion system relying on compctl to call the
> executables analogos to the bash completer.
for the record, as we talked off-line already:
in general nice, and thanks for working on this. Sadly, the compctl is not
compatible with the zsh autoloading mechanisms, as it seems, you'd also need to
install the files at _$exename (in the manager patch), but that alone does not
fixes it.
So either we move to the new completion widget system (man zshcompsys) or pack
all our CLI tools zsh completion in a single file (maybe provided by docs or
manager?) so that an user only needs to source one file. I'd like the compsys
approach more, but it could be a bit more complex, and the return of investment
isn't to big here, so maybe do that only if it doesn't frustrates you and needs
a non-trivial amount of time.
>
> Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
> ---
> src/PVE/CLIHandler.pm | 27 +++++++++++++++++++++++++++
> 1 file changed, 27 insertions(+)
>
> diff --git a/src/PVE/CLIHandler.pm b/src/PVE/CLIHandler.pm
> index 2107108..1d27278 100644
> --- a/src/PVE/CLIHandler.pm
> +++ b/src/PVE/CLIHandler.pm
> @@ -490,6 +490,33 @@ complete -o default -C '$exename bashcomplete' $exename
> __EOD__
> }
>
> +sub generate_zsh_completions {
> + my ($class) = @_;
> +
> + # generate zsh completion config
> +
> + $exename = &$get_exe_name($class);
> +
> + print <<__EOD__;
> +# $exename zsh completion
> +
> +function _$exename() {
> + local words cwords line point cmd curr prev
> + read -Ac words
> + read -cn cwords
> + read -l line
> + read -ln point
> + cmd=\${words[1]}
> + curr=\${words[cwords]}
> + prev=\${words[cwords-1]}
> + reply=(\$(COMP_CWORD="\$cwords" COMP_LINE="\$line" COMP_POINT="\$point" \\
> + $exename bashcomplete "\$cmd" "\$curr" "\$prev"))
> +}
> +
> +compctl -K _$exename $exename
> +__EOD__
> +}
> +
> sub generate_asciidoc_synopsys {
> my ($class) = @_;
> $class->generate_asciidoc_synopsis();
>
More information about the pve-devel
mailing list