tools: Generate per-command bash completion script

The current setup uses a single script that is symlinked twice
and that tries to configure bash completion for both virsh and
virt-admin, even if only one of them is installed. This also
forces us to have a -bash-completion RPM package that only
contains the tiny shared file.

Rework bash completion support so that two scripts are
generated, each one tailored to a specific command.

Since the shared script no longer exists after this change,
the corresponding RPM package becomes empty.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Andrea Bolognani 2021-04-19 18:40:14 +02:00
parent c813acc0df
commit cf66ee8ddc
3 changed files with 17 additions and 17 deletions

View File

@ -1909,9 +1909,6 @@ exit 0
%{_datadir}/libvirt/test-screenshot.png
%files bash-completion
%{_datadir}/bash-completion/completions/vsh
%if %{with_wireshark}
%files wireshark
%{wireshark_plugindir}/libvirt.so

View File

@ -1,11 +1,15 @@
install_data('vsh', install_dir: bash_completion_dir)
completion_commands = [
'virsh',
'virt-admin',
]
meson.add_install_script(
meson_python_prog.path(), python3_prog.path(), meson_install_symlink_prog.path(),
bash_completion_dir, 'vsh', 'virsh',
)
meson.add_install_script(
meson_python_prog.path(), python3_prog.path(), meson_install_symlink_prog.path(),
bash_completion_dir, 'vsh', 'virt-admin',
)
foreach command : completion_commands
completion_conf = configuration_data()
completion_conf.set('command', command)
completion = configure_file(
input: 'vsh.in',
output: command,
configuration: completion_conf,
)
install_data(completion, install_dir: bash_completion_dir)
endforeach

View File

@ -1,8 +1,8 @@
#
# virsh & virt-admin completion command
# @command@ completion support
#
_vsh_complete()
_@command@_complete()
{
local words cword c=0 i=0 cur RO URI CMDLINE INPUT A
@ -62,7 +62,6 @@ _vsh_complete()
__ltrim_colon_completions "$cur"
return 0
} &&
complete -o default -o filenames -F _vsh_complete virsh &&
complete -o default -o filenames -F _vsh_complete virt-admin
complete -o default -o filenames -F _@command@_complete @command@
# vim: ft=sh:et:ts=4:sw=4:tw=80