diff --git a/dnf5/bash-completion/dnf5 b/dnf5/bash-completion/dnf5 index de2745499..1d322d7ba 100644 --- a/dnf5/bash-completion/dnf5 +++ b/dnf5/bash-completion/dnf5 @@ -14,13 +14,24 @@ _do_dnf5_completion() fi mapfile -t COMPREPLY <<<$("${1}" "--complete=${cword}" "${words[@]}") -} -complete_cmds="dnf5" -dnf_target=$(readlink -f "/usr/bin/dnf") + # 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. + # This behavior is fixed by removing the colon-containing prefix from the items in COMPREPLY. + # A side effect is the removal of this prefix in the list of bash completion suggestions. + # + # The preferred solution is to remove the colon ':' from COMP_WORDBREAKS in .bashrc: + # COMP_WORDBREAKS=${COMP_WORDBREAKS//:} + if [[ ${cur} == *:* && ${COMP_WORDBREAKS} == *:* ]]; then + # Remove colon-word prefix from items in COMPREPLY + local _colon_word=${cur%"${cur##*:}"} + COMPREPLY=("${COMPREPLY[@]#"$_colon_word"}") + fi +} -if [ "$dnf_target" = "/usr/bin/dnf5" ]; then - complete_cmds+=" dnf" +_complete_dnf5_cmds="dnf5" +if [ "$(readlink -fn /usr/bin/dnf)" = "/usr/bin/dnf5" ]; then + _complete_dnf5_cmds+=" dnf" fi -complete -F _do_dnf5_completion -o nosort -o nospace $complete_cmds +complete -F _do_dnf5_completion -o nosort -o nospace $_complete_dnf5_cmds