]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tools: Generate per-command bash completion script
authorAndrea Bolognani <abologna@redhat.com>
Mon, 19 Apr 2021 16:40:14 +0000 (18:40 +0200)
committerAndrea Bolognani <abologna@redhat.com>
Thu, 22 Apr 2021 09:01:27 +0000 (11:01 +0200)
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>
libvirt.spec.in
tools/bash-completion/meson.build
tools/bash-completion/vsh.in [moved from tools/bash-completion/vsh with 91% similarity]

index dc54a9f718ed509b3cb2eef35503af751617b04e..8c0d0acf4ec80f35f55a2ef4b4408a1021a1c003 100644 (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
index 8924c93adf565705c47740aaccbdc199da263963..deda7c4f461ef40ece795dbaa8cbb00437dce784 100644 (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
similarity index 91%
rename from tools/bash-completion/vsh
rename to tools/bash-completion/vsh.in
index 402945a8c5d81b246eb030ae51f8b9ee113e660f..70ade50a02cc43945a7cd68e85d2c56c200cdd1d 100644 (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