Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix colon in bash completion #1984

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions dnf5/bash-completion/dnf5
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading