completion: Invoke the command being completed

As suggested by Ville Skyttä in
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4012#note_2084405,
make sure to invoke the copy of the command which is being completed
when asking for completions of a given subcommand.

This avoids accidentally invoking any old `gdbus`/`gresource`/etc.
binary which is hanging around in another part of `$PATH`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
Philip Withnall
2024-04-17 15:08:43 +01:00
parent 869ef92858
commit cc22637856
5 changed files with 24 additions and 14 deletions

View File

@@ -7,7 +7,8 @@
####################################################################################################
__gresource() {
local choices coffset
local choices coffset gresource_binary
gresource_binary="$1"
if [ "${COMP_CWORD}" -gt 2 ]; then
if [ "${COMP_WORDS[1]}" = --section ]; then
@@ -45,7 +46,7 @@ __gresource() {
3)
case "${COMP_WORDS[$((coffset+1))]}" in
list|details|extract)
choices="$(gresource list "${COMP_WORDS[$((coffset+2))]}" 2> /dev/null | sed -e 's.$. .')"
choices="$("$gresource_binary" list "${COMP_WORDS[$((coffset+2))]}" 2> /dev/null | sed -e 's.$. .')"
;;
esac
;;