Fix fzf's ssh host completion under failglob in bash

fzf's completion.bash globs ~/.ssh/config.d/* when listing hosts
=> With `shopt -s failglob`, a missing or empty folder makes this
   an expansion error, printing "bash: no match" on every <Tab>
   after `ssh`

Define __fzf_list_hosts before sourcing fzf, using its override
hook with bash-completion's host list, as fzf itself suggests
This commit is contained in:
Alexander Hess 2026-10-06 13:36:07 +02:00
commit 7cf5654a4b
Signed by: alexander
GPG key ID: B46EDB4DFC26805D

View file

@ -16,6 +16,17 @@ complete -W '--quieter' generate-shell-completions
# #
# Must be sourced before `complete_alias` below, # Must be sourced before `complete_alias` below,
# which then saves fzf's wrappers as the vanilla completions # which then saves fzf's wrappers as the vanilla completions
#
# fzf's own host list globs ~/.ssh/config.d/*,
# which aborts under `failglob` if that folder is empty or missing
# => Use fzf's override hook with `bash-completion`'s host list instead
__fzf_list_hosts() {
local COMPREPLY=()
_known_hosts_real ''
printf '%s\n' "${COMPREPLY[@]}" | command sort -u --version-sort
}
if [ -r /usr/share/doc/fzf/examples/completion.bash ]; then if [ -r /usr/share/doc/fzf/examples/completion.bash ]; then
. /usr/share/doc/fzf/examples/completion.bash . /usr/share/doc/fzf/examples/completion.bash
fi fi