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 %{_datadir}/libvirt/test-screenshot.png
%files bash-completion
%{_datadir}/bash-completion/completions/vsh
%if %{with_wireshark} %if %{with_wireshark}
%files wireshark %files wireshark
%{wireshark_plugindir}/libvirt.so %{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( foreach command : completion_commands
meson_python_prog.path(), python3_prog.path(), meson_install_symlink_prog.path(), completion_conf = configuration_data()
bash_completion_dir, 'vsh', 'virsh', completion_conf.set('command', command)
) completion = configure_file(
input: 'vsh.in',
meson.add_install_script( output: command,
meson_python_prog.path(), python3_prog.path(), meson_install_symlink_prog.path(), configuration: completion_conf,
bash_completion_dir, 'vsh', 'virt-admin', )
) 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 local words cword c=0 i=0 cur RO URI CMDLINE INPUT A
@ -62,7 +62,6 @@ _vsh_complete()
__ltrim_colon_completions "$cur" __ltrim_colon_completions "$cur"
return 0 return 0
} && } &&
complete -o default -o filenames -F _vsh_complete virsh && complete -o default -o filenames -F _@command@_complete @command@
complete -o default -o filenames -F _vsh_complete virt-admin
# vim: ft=sh:et:ts=4:sw=4:tw=80 # vim: ft=sh:et:ts=4:sw=4:tw=80