Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Update _virsh completion



Daniel Shahaf wrote on Fri, Sep 02, 2016 at 18:20:24 +0000:
> Marko Myllynen wrote on Fri, Sep 02, 2016 at 12:36:44 +0300:
> > Looks like 'libvirtd\:///system' instead of 'libvirtd:///system' is
> > passed to virt-admin without (Q). Perhaps there's more optimal/safe
> > alternative here which I'm missing?
> > 
> 
> I'm not sure why the colon gets escaped.  Typically, colons get escaped
> when constructing a spec argument to _arguments or _describe.

The colon is escaped by _arguments:
.
                                        For options that have more than one
              argument these are given as one string, separated by colons.
              All colons in the original arguments are preceded with
              backslashes.
.
By "more than one argument" the manual refers to specs such as
«_arguments : -c:arg1:_users:arg2:_hosts».  This spec means -c takes
two arguments in separate words.   (Example: «foo -c danielsh localhost»
would yield «opt_args=(-c danielsh:localhost)».)

Undoing that escaping would be:

diff --git a/Completion/Unix/Command/_libvirt b/Completion/Unix/Command/_libvirt
index ad4c3b8..f887426 100644
--- a/Completion/Unix/Command/_libvirt
+++ b/Completion/Unix/Command/_libvirt
@@ -116,6 +116,7 @@ esac
 local -a conn_opt
 if [[ -n ${(v)opt_args[(I)-c|--connect]} ]]; then
   local uri=${(v)opt_args[(I)-c|--connect]}
+  uri=${uri//(#m)\\([\\:])/${MATCH[2]}} # opt_args elements are colon-escaped
   # For the libvirt remote URI syntax, see:
   # https://libvirt.org/guide/html/Application_Development_Guide-Architecture-Remote_URIs.html
   [[ -z ${(Q)uri//([[:alnum:]]|+|:|\/|@|-|\.|\?|=)} ]] && \

This patch changes the behaviour of «virsh -c qemu\:///system start
--domain <TAB>».

See also the _arguments email I'm about to send.

Cheers,

Daniel



Messages sorted by: Reverse Date, Date, Thread, Author