]> xenbits.xensource.com Git - libvirt.git/commitdiff
vsh: Fix completion error in case of multiple mac addresses
authorLin Ma <lma@suse.com>
Tue, 10 Nov 2020 09:50:59 +0000 (17:50 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 10 Nov 2020 17:34:18 +0000 (18:34 +0100)
We know that the bash completer automatically handle colon by preceding
it with an escape character backslash.
While our bash autompletion file vsh completes multiple items, In case
there're multiple items which have same prefix and the content of completion
items contain colon(say mac address), The vsh needs to correctly hands
the backslash which are added by bash completer, Otherwise the completion
won't be successful. This patch fixes this problem.

e.g.:

 # virsh domiflist --domain VM
 Interface   Type      Source    Model    MAC
-------------------------------------------------------------
 vnet0       network   default   virtio   52:54:00:fb:7b:f5
 vnet1       bridge    br0       virtio   52:54:00:80:1b:21

Before:
 # virsh detach-interface --domain VM --mac <TAB>
 # virsh detach-interface --domain VM --mac 52\:54\:00\:<TAB><TAB>

After:
 # virsh detach-interface --domain VM --mac <TAB>
 # virsh detach-interface --domain VM --mac 52\:54\:00\:<TAB><TAB>
 52:54:00:80:1b:21  52:54:00:fb:7b:f5
 # virsh detach-interface --domain VM --mac 52\:54\:00\:

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

index 8493cad28b98645ef9753f5e011c7a8a94b23857..fb38e8616fab9af2dc51049a4693cf37be2ba1b1 100644 (file)
@@ -39,6 +39,7 @@ _vsh_complete()
     fi
 
     INPUT=( "${COMP_WORDS[@]:$i:$COMP_CWORD}" )
+    INPUT[-1]=${INPUT[-1]//\\:/:}
 
     # Uncomment these lines for easy debug.
 #    echo;