[pve-devel] [PATCH common] Fix 1891: Add zsh tab completion script generator

Christian Ebner c.ebner at proxmox.com
Fri Feb 8 16:41:40 CET 2019


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.

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();
-- 
2.11.0



More information about the pve-devel mailing list