Skip to content

Commit

Permalink
DNF5 bash completion: "menu completion" support
Browse files Browse the repository at this point in the history
"Menu completion" cyclically completes the suggestions from the list.
We don't want to add a description to the added argument -> We need
a list of suggestions without descriptions.

"Normal completion" completes an identical part of the suggestions.
The added description is not printed. -> Descriptions can be
in the suggestion list, but will not be used. We can optimize the code
and not add the descriptions to the list.
  • Loading branch information
jrohel committed Jan 23, 2025
1 parent 921d222 commit dbd5fa3
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion dnf5/bash-completion/dnf5
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,18 @@ _do_dnf5_completion()
_init_completion -n "><=;|&(:" -- "$@" || return
fi

mapfile -t COMPREPLY <<<$("${1}" "--complete=${cword}" "${words[@]}")
case ${COMP_TYPE} in
# <TAB> (code 9) - normal completion, the identical part of the suggestions is completed
# '%' (code 37) - menu completion, cyclically completes the suggestions from the list
# In these cases the list of suggestions is not printed and we do not want
# to complete the argument with a description (help).
9 | 37)
mapfile -t COMPREPLY <<<$("${1}" "--complete=${cword},add_description=0" "${words[@]}")
;;
*)
mapfile -t COMPREPLY <<<$("${1}" "--complete=${cword}" "${words[@]}")
;;
esac

# In Bash, with a colon in COMP_WORDBREAKS, words containing colons are
# always completed as entire words if the word to complete contains a colon.
Expand Down

0 comments on commit dbd5fa3

Please sign in to comment.