Update in 2013: Most of bash-completion was rewritten to autoload completions only when needed. The core script is much ligher now.
The completion script can sometimes be huge in shell script standards. On one servers I have access to, it's almost 1700 lines (57 KB) and that's just the core script. In /etc/bash_completion.d
there are ~200 additional scripts for various other commands (openssl
, mutt
, mount
...) totalling 25537 lines or 1.2 MB. Each script, when sourced, checks if a command is actually available before defining completion handlers; ~330 times in this case, each of which involves checking $PATH
for an executable file with a given name. (Although I would expect /usr/bin
to be cached in memory...)
Admittedly, even that only takes half a second to load, not two full seconds. But it might be at least part of the problem. Run du -hs /etc/bash_completion*
or wc -l /etc/bash_completion{,.d/*} | grep total
if you want to check.
You can try manually sourcing the script, in "trace" mode:
set -x
. /etc/bash_completion
You'll see each line as it is executed. If there's a particular command that takes a long time, you should notice it.
(set +x
disables the trace mode.)
is this /bin/bash ? - try /bin/dash might be a bit quicker. – Sirex – 2011-04-07T12:40:34.360
3This is why I deinstalled bash-completion – Vi. – 2011-04-07T13:47:15.063