Technically, this is a v2 of [1], but this implements the feature from different angle and therefore it's a start of new series. What's implemented? =================== Auto completion for both interactive and non-interactive virsh/virt-admin. Known limitations ================= Currently, just options completers work. I mean, to bring up list of domains you have to: virsh # start --domain <TAB><TAB> Doing bare: virsh # start <TAB><TAB> brings up list of --options. With the new approach implemented here it should be easy to implement this. But that can be saved for later. How to test this? ================= Interactive completion should work out of the box. Just make sure you're connected. Completers don't connect! You certainly don't want ssh's 'Password:' prompt show on <TAB><TAB>, do you? Non-interactive completers do connect, but in order to avoid any password prompts, /dev/stdin is closed before anything else is done. In order to test it, just: libvirt.git $ source tools/bash-completion/vsh Now, bash completion should work: libvirt.git $ ./tools/virsh -c qemu:///system start --domain <TAB><TAB> Notes ===== As usual, you can find all the patches on my github [2]. I've tried to work in all the review suggestions from v1. Due to changes in design (reusing parse code instead of duplicating it) not all suggestions were possible to work in though. Michal 1: https://www.redhat.com/archives/libvir-list/2017-November/msg00213.html 2: https://github.com/zippy2/libvirt/tree/bash_autocomplete_v3 (yeah v3, don't ask) Michal Privoznik (18): vsh: Drop useless check for opts != NULL vsh: Drop useless check for cmd != NULL vshCommandParse: Don't leak @tkdata vshCommandStringParse: Allow retrieving partial result vshReadlineParse: Drop code duplication vshReadlineParse: Escape returned results if needed vshReadlineParse: Use string list vshCommandOpt: Allow caller avoiding assert() util: Introduce virStringListMerge vsh: Fix vshCompleter signature vsh: Call vshCmdOptDef completer vsh: Prune string list returned by completer vsh: Filter --options vsh: Introduce complete command tools: Provide bash autompletion file virsh: Introduce virshDomainNameCompleter virsh: Introduce virshDomainInterfaceCompleter virt-admin: Introduce vshAdmServerCompleter configure.ac | 3 + libvirt.spec.in | 3 + m4/virt-bash-completion.m4 | 74 +++++ src/libvirt_private.syms | 1 + src/util/virstring.c | 36 +++ src/util/virstring.h | 3 + tools/Makefile.am | 40 ++- tools/bash-completion/vsh | 67 +++++ tools/virsh-completer.c | 150 ++++++++++ tools/virsh-completer.h | 41 +++ tools/virsh-domain-monitor.c | 33 ++- tools/virsh-domain.c | 186 ++++++------ tools/virsh-snapshot.c | 24 +- tools/virsh.c | 5 +- tools/virsh.h | 7 +- tools/virt-admin-completer.c | 76 +++++ tools/virt-admin-completer.h | 33 +++ tools/virt-admin.c | 13 +- tools/vsh.c | 663 ++++++++++++++++++++++++++----------------- tools/vsh.h | 23 +- 20 files changed, 1097 insertions(+), 384 deletions(-) create mode 100644 m4/virt-bash-completion.m4 create mode 100644 tools/bash-completion/vsh create mode 100644 tools/virsh-completer.c create mode 100644 tools/virsh-completer.h create mode 100644 tools/virt-admin-completer.c create mode 100644 tools/virt-admin-completer.h -- 2.13.6 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list