From: Werner Fink <werner@suse.de>
Date: Thu, 29 Feb 2024 10:07:58 +000
Subject: Make bash completion work with version 2.12 and before 2.11

Note that the shell function have() had become deprecated with 2.11
and had been removed from 2.12 which is now providing _comp_have_command()

resolves boo#1220626

---
 util/bash-completion.d/grub-completion.bash.in |   38 ++++++++++++++++---------
 1 file changed, 25 insertions(+), 13 deletions(-)

--- a/util/bash-completion.d/grub-completion.bash.in
+++ b/util/bash-completion.d/grub-completion.bash.in	2024-02-29 10:04:52.197876569 +0000
@@ -17,6 +17,18 @@
 # along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 # bash completion for grub
 
+if test "$(type -t _comp_have_command)" = function
+then
+    _have() {
+        _comp_have_command $1
+    }
+elif test "$(type -t have)" = function
+then
+    _have() {
+        have $1
+    }
+fi
+
 __grub_dir() {
     local i c=1 boot_dir
 
@@ -177,12 +189,12 @@ _grub_set_entry () {
 }
 
 __grub_set_default_program="@grub_set_default@"
-have ${__grub_set_default_program} && \
+_have ${__grub_set_default_program} && \
     complete -F _grub_set_entry -o filenames ${__grub_set_default_program}
 unset __grub_set_default_program
 
 __grub_reboot_program="@grub_reboot@"
-have ${__grub_reboot_program} && \
+_have ${__grub_reboot_program} && \
  complete -F _grub_set_entry -o filenames ${__grub_reboot_program}
 unset __grub_reboot_program
 
@@ -209,7 +221,7 @@ _grub_editenv () {
 }
 
 __grub_editenv_program="@grub_editenv@"
-have ${__grub_editenv_program} && \
+_have ${__grub_editenv_program} && \
  complete -F _grub_editenv -o filenames ${__grub_editenv_program}
 unset __grub_editenv_program
 
@@ -230,7 +242,7 @@ _grub_mkconfig () {
     fi
 }
 __grub_mkconfig_program="@grub_mkconfig@"
-have ${__grub_mkconfig_program} && \
+_have ${__grub_mkconfig_program} && \
  complete -F _grub_mkconfig -o filenames ${__grub_mkconfig_program}
 unset __grub_mkconfig_program
 
@@ -265,12 +277,12 @@ _grub_setup () {
 }
 
 __grub_bios_setup_program="@grub_bios_setup@"
-have ${__grub_bios_setup_program} && \
+_have ${__grub_bios_setup_program} && \
  complete -F _grub_setup -o filenames ${__grub_bios_setup_program}
 unset __grub_bios_setup_program
 
 __grub_sparc64_setup_program="@grub_sparc64_setup@"
-have ${__grub_sparc64_setup_program} && \
+_have ${__grub_sparc64_setup_program} && \
  complete -F _grub_setup -o filenames ${__grub_sparc64_setup_program}
 unset __grub_sparc64_setup_program
 
@@ -316,7 +328,7 @@ _grub_install () {
     fi
 }
 __grub_install_program="@grub_install@"
-have ${__grub_install_program} && \
+_have ${__grub_install_program} && \
  complete -F _grub_install -o filenames ${__grub_install_program}
 unset __grub_install_program
 
@@ -338,7 +350,7 @@ _grub_mkfont () {
     fi
 }
 __grub_mkfont_program="@grub_mkfont@"
-have ${__grub_mkfont_program} && \
+_have ${__grub_mkfont_program} && \
  complete -F _grub_mkfont -o filenames ${__grub_mkfont_program}
 unset __grub_mkfont_program
 
@@ -369,7 +381,7 @@ _grub_mkrescue () {
     fi
 }
 __grub_mkrescue_program="@grub_mkrescue@"
-have ${__grub_mkrescue_program} && \
+_have ${__grub_mkrescue_program} && \
  complete -F _grub_mkrescue -o filenames ${__grub_mkrescue_program}
 unset __grub_mkrescue_program
 
@@ -411,7 +423,7 @@ _grub_mkimage () {
     fi
 }
 __grub_mkimage_program="@grub_mkimage@"
-have ${__grub_mkimage_program} && \
+_have ${__grub_mkimage_program} && \
  complete -F _grub_mkimage -o filenames ${__grub_mkimage_program}
 unset __grub_mkimage_program
 
@@ -433,7 +445,7 @@ _grub_mkpasswd_pbkdf2 () {
     fi
 }
 __grub_mkpasswd_pbkdf2_program="@grub_mkpasswd_pbkdf2@"
-have ${__grub_mkpasswd_pbkdf2_program} && \
+_have ${__grub_mkpasswd_pbkdf2_program} && \
  complete -F _grub_mkpasswd_pbkdf2 -o filenames ${__grub_mkpasswd_pbkdf2_program}
 unset __grub_mkpasswd_pbkdf2_program
 
@@ -471,7 +483,7 @@ _grub_probe () {
     fi
 }
 __grub_probe_program="@grub_probe@"
-have ${__grub_probe_program} && \
+_have ${__grub_probe_program} && \
  complete -F _grub_probe -o filenames ${__grub_probe_program}
 unset __grub_probe_program
 
@@ -493,7 +505,7 @@ _grub_script_check () {
     fi
 }
 __grub_script_check_program="@grub_script_check@"
-have ${__grub_script_check_program} && \
+_have ${__grub_script_check_program} && \
  complete -F _grub_script_check -o filenames ${__grub_script_check_program}
 
 
