I am in the same situation and investigated the root cause.
The completion code invokes
brew commands --quiet internally. Therefore you have to wait ruby interpreter to be ready and execute the commands. No doubt it’s slow.
( the code is here )
I modified the completion code in my environments like below.
It saves the
brew commands result to a file and use it for subsequent completion.
It’s not fast nor ideal but acceptable for me.
if [[ "$i" -eq "$COMP_CWORD" ]]
# Do not auto-complete "*instal" or "*uninstal" aliases for "*install" commands.
# Prefix newline to prevent not checking the first command.
local commands_cache="$(brew --prefix)/Homebrew/completions/bash/commands_cache"
[[ -r "$commands_cache" ]] \
&& cmds=$(cat "$commands_cache") \
|| cmds=$'\n'"$(brew commands --quiet --include-aliases | \grep -v instal$ | tee "$commands_cache")"