Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I don't understand why bash completion is loaded so slow on my MacBook Pro.

I did the following in my ~/.bash_profile:

echo "Loading BashCompletion..."
if [ -f /opt/local/etc/bash_completion ]; then
    . /opt/local/etc/bash_completion
echo "BashCompletion loaded."

the execution time for bash_completion typically is > 2 seconds.

I find that really annoying when I am working on the terminal which requires me to constantly open new tabs.

Is there a way I can cache this or something?

(Note I am using iTerm2 and this is equally slow on the original terminal in Mac as well).

share|improve this question
That should not be happening. Am I correct you use MacPort's bash completion? – slhck Jul 15 '11 at 20:27
What does that file you load look like? – Daniel Beck Jul 15 '11 at 20:48
@slhck: Yes I am indeed using macport's bash completion – disappearedng Jul 15 '11 at 21:17
@Daniel: Everything is fine except for this. I profiled almost every line. – disappearedng Jul 15 '11 at 21:17
I experience the same slowness and I'm using Homebrew. – Brice Jan 30 '12 at 11:52

If you're running MacPorts >= 2.1.2 and Mountain Lion it seems your bash_profile is wrong. Follow the instructions on How to get git-completion.bash to work on Mac OS X?. I assume that could speed up the auto-completion.

Another solution would be to try installing auto-complete via Fink or Homebrew. If that doesn´t work, you could try another shell altogether. I've found that Fish shell is outstanding when it comes to auto-completion (out of the box). Though version 2 is still in beta I would highly recommend it.

share|improve this answer

I'm going to guess that your bash is too old. I'm running stock bash that came with Mountain Lion and here's what I see:

$ port info bash-completion
bash-completion @2.0, Revision 1 (sysutils)

Description:          Programmable completion library for bash. This port
                      **requires bash >=4.1** and is meant to be used together with
                      the bash port.

Runtime Dependencies: bash
Conflicts with:       bash-completion-devel
Platforms:            darwin
License:              GPL-2+

$ bash --version
GNU bash, version **3.2.48(1)-release (x86_64-apple-darwin12)**
Copyright (C) 2007 Free Software Foundation, Inc.
share|improve this answer
I don't see to have this port command. :( How do I find out which git tab completion software is running on my mac. – Dean Hiller Aug 14 '14 at 16:13
@DeanHiller This answer is referring to the Macports package manager, which provides the port command. Macports's bash completion app will be newer than the one provided with OS X. – Matt S Aug 25 '14 at 16:12

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 .bash_profile file.

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 /usr/local/etc/bash_completion.d directory.

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.