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

Re: zsh virsh completion



Marko Myllynen wrote:
> Below is a patch to implement basic completion for the virsh(1) [1]
> command from libvirt [2], it completes all virsh commands and their
> respective options.

The function should probably be named _libvirt then - in much the same
way as we use e.g. _subversion for svn.

> - virsh help <command> output is pretty much like --help output of any
> other program, is there a trick to make the option descriptions also
> available when completing virsh command options?

If you don't use _arguments --, you can parse the output manually.

> - would it make sense (or is it perhaps already possible somehow) to
> optionally enable "best guess" completion for all commands which have
> no command specific completion rules available yet? There are lots of

There are commands where running the command with --help/-h or
whatever could do something destructive. I forget which command it
was but I remember years ago finding that a completion was spewing
messages into syslog. If it was going to be a catch-all default,
it might be safer to use man pages as the source.

> +_arguments -A "-*" -C -S -s -w \

-w, really? That's rare.

> +  _cache_virsh_cmds=( ${="$(virsh help 2>&1 | awk '!/:/ {print $1}')"} )

You should use _call_program as a wrapper around virsh.

> +    _values -w options ${=_cache_virsh_cmdopts[$cmd]} && ret=0

I'm not convinced that _values is gaining you anything over a plain
compadd (with _wanted). I wouldn't typically use it with generated
matches. If you want the duplicate removal, use -F words

With this in place there's no filename completion which can be quite
annoying if you need to complete files. So unless virsh sub-commands
never take filenames as arguments, I'd have it fallback to _default.
In this case, using _alternative.  Also, for option completion, it
should check the prefix-needed style.

Oliver



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