]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: Conditionally Ignore the first entry in list of completions
authorLin Ma <lma@suse.com>
Tue, 8 May 2018 14:20:31 +0000 (22:20 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 10 May 2018 07:05:46 +0000 (09:05 +0200)
The first entry in the returned array is the substitution for TEXT. It
causes unnecessary output if other commands or options share the same
prefix, e.g.

$ virsh des<TAB><TAB>
des      desc     destroy

or

$ virsh domblklist --d<TAB><TAB>
--d        --details  --domain

This patch fixes the above issue.

Signed-off-by: Lin Ma <lma@suse.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
tools/vsh.c

index 73ec007e562285cefa4742c94f071ae00795fb78..68f3cd99f9b4ef173fcd69972c3289c530b543db 100644 (file)
@@ -3493,7 +3493,10 @@ cmdComplete(vshControl *ctl, const vshCmd *cmd)
     if (!(matches = vshReadlineCompletion(arg, 0, 0)))
         goto cleanup;
 
-    for (iter = matches; *iter; iter++)
+    /* According to rl_completion_matches documentation, the
+     * first entry in @matches array is some dummy substitution
+     * string for @arg. Skip it. */
+    for (iter = &matches[1]; *iter; iter++)
         printf("%s\n", *iter);
 
     ret = true;