Short version: Removing a single line from
/usr/local/etc/bash_completion reduced the time to open a new tab from ten seconds to a quarter of a second. Read on for details.
I'm using bash-completion from homebrew and encountered the same problem. It was taking over ten seconds to load the bash completion scripts each time I opened a terminal.
Most of that time, it seems is taken up by a single line in the
have() function: a call to
type to determine if a command-line program is installed.
With the default
have() function and all of the provided bash completion scripts in place, it would take 10.561s to load the scripts (reported by prefixing
time to the
. /opt/local/etc/bash_completion line in my
After commending out the
PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin type $1 &>/dev/null && line of my
/usr/local/etc/bash_completion script (leaving the
have=yes line, opening a new terminal takes only 0.258s. This time could be reduced further by removing unnecessary completion scripts (symlinks) from the
I don't know why the call to
type is taking so long. I'm investigating that next.
One potential downside to this approach is that it will cause bash completion functions to be loaded into memory even though you have no use for them. The
have() function checks to see if a command or application is installed. If it's not, the completion script generally decides not to bother loading itself because it will be of no use.
At the moment, I'm happy with the tradeoff but I will continue to explore the
type problem as I get time. I'll update my answer if I find a better solution.