Re: [libvirt] virsh bash completion file
Quoting Daniel P. Berrange (berra...@redhat.com): > On Thu, Oct 06, 2011 at 08:30:55AM -0500, Serge E. Hallyn wrote: > > Quoting Daniel P. Berrange (berra...@redhat.com): > > > On Wed, Oct 05, 2011 at 03:17:47PM -0500, Serge E. Hallyn wrote: > > > > Hi, > > > > > > > > I've been trying out a bash autocompletion file by Geoff Low (slight > > > > hack > > > > by me, don't blame him for my hack), and it's working pretty nicely. > > > > I'm not sure where to put it in the git tree, but it seems like it'd be > > > > nice to have upstream? > > > > > > David Lutterkort previously suggested this > > > > > >https://www.redhat.com/archives/libvir-list/2007-October/msg00231.html > > > > > > And I didn't ever notice that and so wrote one myself > > > > > >https://www.redhat.com/archives/libvir-list/2008-July/msg00175.html > > >https://www.redhat.com/archives/libvir-list/2008-July/msg00177.html > > > > > > Neither ever got committed. There were some things I didn't much like > > > about mine, but I can't really remember now. > > > > > > Third time lucky perhaps :-) > > > > So the things you didn't much like must not have been *too* bad? :) > > Are you going to make some changes and resubmit, or would you like > > me to test (and port as needed) the above patches first? > > I don't have time right now to update my own patches. You, or anyone > else, are free to take them forward as desired... Well I've got the patch ported so that it mostly works - autocompletes for commands and vm names at least. (ugly patch against 0.9.8 attached just for conversation) But I can't figure out how one should do uri completion. Any hints on where to get such a list now? thanks, -serge Index: libvirt-0.9.8/include/libvirt/libvirt.h === --- libvirt-0.9.8.orig/include/libvirt/libvirt.h2011-12-08 06:58:49.0 + +++ libvirt-0.9.8/include/libvirt/libvirt.h 2012-02-08 03:52:16.008232120 + @@ -1065,6 +1065,7 @@ unsigned int flags); int virConnectRef (virConnectPtr conn); int virConnectClose (virConnectPtr conn); +char ** virConnectURIs (int *nuris); const char *virConnectGetType (virConnectPtr conn); int virConnectGetVersion(virConnectPtr conn, unsigned long *hvVer); Index: libvirt-0.9.8/include/libvirt/libvirt.h.in === --- libvirt-0.9.8.orig/include/libvirt/libvirt.h.in 2011-12-06 08:38:51.0 + +++ libvirt-0.9.8/include/libvirt/libvirt.h.in 2012-02-08 03:52:35.132225305 + @@ -1065,6 +1065,7 @@ unsigned int flags); int virConnectRef (virConnectPtr conn); int virConnectClose (virConnectPtr conn); +char ** virConnectURIs (int *nuris); const char *virConnectGetType (virConnectPtr conn); int virConnectGetVersion(virConnectPtr conn, unsigned long *hvVer); Index: libvirt-0.9.8/libvirt.spec.in === --- libvirt-0.9.8.orig/libvirt.spec.in 2011-12-08 06:54:48.0 + +++ libvirt-0.9.8/libvirt.spec.in 2012-02-08 03:54:03.300230906 + @@ -1050,6 +1050,7 @@ %{_unitdir}/libvirtd.service %endif %doc daemon/libvirtd.upstart +%{_sysconfdir}/bash_completion.d/virsh %config(noreplace) %{_sysconfdir}/sysconfig/libvirtd %config(noreplace) %{_sysconfdir}/libvirt/libvirtd.conf %if 0%{?fedora} >= 14 || 0%{?rhel} >= 6 Index: libvirt-0.9.8/src/Makefile.am === --- libvirt-0.9.8.orig/src/Makefile.am 2012-02-08 03:46:38.0 + +++ libvirt-0.9.8/src/Makefile.am 2012-02-08 20:51:04.340232096 + @@ -22,7 +22,9 @@ $(COVERAGE_CFLAGS) AM_LDFLAGS = $(COVERAGE_LDFLAGS) -EXTRA_DIST = $(conf_DATA) util/keymaps.csv +bashdir = $(sysconfdir)/bash_completion.d + +EXTRA_DIST = $(conf_DATA) util/keymaps.csv virsh.bash BUILT_SOURCES = CLEANFILES = @@ -1584,6 +1586,8 @@ $(DESTDIR)$(sysconfdir)/libvirt/qemu/networks/default.xml && \ rm $(DESTDIR)$(sysconfdir)/libvirt/qemu/networks/default.xml.t; } endif + $(MKDIR_P) "$(DESTDIR)$(bashdir)" + $(INSTALL_DATA) "$(srcdir)/virsh.bash" "$(DESTDIR)$(bashdir)/virsh" uninstall-local:: rmdir "$(DESTDIR)$(localstatedir)/cache/libvirt" ||: @@ -1621,6 +1625,7 @@ rmdir "$(DESTDIR)$(localstatedir)/run/libvirt/network" ||: endif rmdir "$(DESTDIR)$(localstatedir)/lib/libvirt" ||: + rm -f "$(DESTDIR)$(bashdir)/virsh" ||: CLEANFILES += *.gcov .lib
Re: [libvirt] virsh bash completion file
On Thu, Oct 06, 2011 at 08:30:55AM -0500, Serge E. Hallyn wrote: > Quoting Daniel P. Berrange (berra...@redhat.com): > > On Wed, Oct 05, 2011 at 03:17:47PM -0500, Serge E. Hallyn wrote: > > > Hi, > > > > > > I've been trying out a bash autocompletion file by Geoff Low (slight hack > > > by me, don't blame him for my hack), and it's working pretty nicely. > > > I'm not sure where to put it in the git tree, but it seems like it'd be > > > nice to have upstream? > > > > David Lutterkort previously suggested this > > > >https://www.redhat.com/archives/libvir-list/2007-October/msg00231.html > > > > And I didn't ever notice that and so wrote one myself > > > >https://www.redhat.com/archives/libvir-list/2008-July/msg00175.html > >https://www.redhat.com/archives/libvir-list/2008-July/msg00177.html > > > > Neither ever got committed. There were some things I didn't much like > > about mine, but I can't really remember now. > > > > Third time lucky perhaps :-) > > So the things you didn't much like must not have been *too* bad? :) > Are you going to make some changes and resubmit, or would you like > me to test (and port as needed) the above patches first? I don't have time right now to update my own patches. You, or anyone else, are free to take them forward as desired... Daniel -- |: http://berrange.com -o-http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] virsh bash completion file
Quoting Daniel P. Berrange (berra...@redhat.com): > On Wed, Oct 05, 2011 at 03:17:47PM -0500, Serge E. Hallyn wrote: > > Hi, > > > > I've been trying out a bash autocompletion file by Geoff Low (slight hack > > by me, don't blame him for my hack), and it's working pretty nicely. > > I'm not sure where to put it in the git tree, but it seems like it'd be > > nice to have upstream? > > David Lutterkort previously suggested this > >https://www.redhat.com/archives/libvir-list/2007-October/msg00231.html > > And I didn't ever notice that and so wrote one myself > >https://www.redhat.com/archives/libvir-list/2008-July/msg00175.html >https://www.redhat.com/archives/libvir-list/2008-July/msg00177.html > > Neither ever got committed. There were some things I didn't much like > about mine, but I can't really remember now. > > Third time lucky perhaps :-) So the things you didn't much like must not have been *too* bad? :) Are you going to make some changes and resubmit, or would you like me to test (and port as needed) the above patches first? thanks, -serge -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] virsh bash completion file
On Wed, Oct 05, 2011 at 02:33:44PM -0600, Eric Blake wrote: > On 10/05/2011 02:17 PM, Serge E. Hallyn wrote: > >Hi, > > > >I've been trying out a bash autocompletion file by Geoff Low (slight hack > >by me, don't blame him for my hack), and it's working pretty nicely. > >I'm not sure where to put it in the git tree, but it seems like it'd be > >nice to have upstream? > > What I'd rather have upstream is: > > virsh completion args... > > which outputs one string per line of valid completions given the > context of args. Then we could leverage a single completion code > both from bash and from the virsh interactive shell; also, you'd > only have to write the bash completion routines once (figure out how > to make it call into 'virsh completion'), rather than chasing a > moving target (update the bash completion every time new virsh > commands and flags are added). The patch I wrote tried todo something similar to that, adding a bunch of hidden '_complete-XXX' commands. https://www.redhat.com/archives/libvir-list/2008-July/msg00175.html it was still a little bit too manual for my liking though. It'd be nice if we could do a completion command that is properly metadata driven from the command arg type data Daniel -- |: http://berrange.com -o-http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] virsh bash completion file
On Wed, Oct 05, 2011 at 03:17:47PM -0500, Serge E. Hallyn wrote: > Hi, > > I've been trying out a bash autocompletion file by Geoff Low (slight hack > by me, don't blame him for my hack), and it's working pretty nicely. > I'm not sure where to put it in the git tree, but it seems like it'd be > nice to have upstream? David Lutterkort previously suggested this https://www.redhat.com/archives/libvir-list/2007-October/msg00231.html And I didn't ever notice that and so wrote one myself https://www.redhat.com/archives/libvir-list/2008-July/msg00175.html https://www.redhat.com/archives/libvir-list/2008-July/msg00177.html Neither ever got committed. There were some things I didn't much like about mine, but I can't really remember now. Third time lucky perhaps :-) Daniel -- |: http://berrange.com -o-http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] virsh bash completion file
Quoting Eric Blake (ebl...@redhat.com): > While I'd love to see better bash completion support, I think that > we should be going about it by fixing virsh to make it easier to > query what completions make sense, so I'm not going to spend much > time further reviewing this. Of course, others are free to use this Thanks, Eric, makes sense. -serge -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] virsh bash completion file
On 10/05/2011 02:17 PM, Serge E. Hallyn wrote: Hi, I've been trying out a bash autocompletion file by Geoff Low (slight hack by me, don't blame him for my hack), and it's working pretty nicely. I'm not sure where to put it in the git tree, but it seems like it'd be nice to have upstream? What I'd rather have upstream is: virsh completion args... which outputs one string per line of valid completions given the context of args. Then we could leverage a single completion code both from bash and from the virsh interactive shell; also, you'd only have to write the bash completion routines once (figure out how to make it call into 'virsh completion'), rather than chasing a moving target (update the bash completion every time new virsh commands and flags are added). VIRSH=$(which virsh) Not quite right. Rather, this should be an add-on to the bash-completion project, at which point you are writing a dropin for /etc/bash_completion.d/virsh, and where you start life with: # helper functions... have virsh && _virsh() { ... main completion } && complete -F _virsh virsh function get_main_option_list Don't use this obsolete syntax. Stick to the POSIX function syntax (look at existing files in /etc/bash_completion.d for pointers, or see my above example of _virsh(){}). { # assume options are specified as [--option1 | --option2 | ...] OPTIONS=$(${VIRSH} help | grep '|' | sed -e 's/.*\[\(.*\)\]/\1/g;s/|//g') To some extent, bash_completion already offers some helper functions that can already do this work for most applications, without having to reinvent the wheel. Furthermore, this doesn't work - it matches nothing: $ virsh help | grep '|' $ While I'd love to see better bash completion support, I think that we should be going about it by fixing virsh to make it easier to query what completions make sense, so I'm not going to spend much time further reviewing this. Of course, others are free to use this in the interim, while we still lack decent virsh support. -- Eric Blake ebl...@redhat.com+1-801-349-2682 Libvirt virtualization library http://libvirt.org -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list