As a recent switcher from Ubuntu (Well recent switch backer if that's a word) I'm finding myself in the command line a lot more than when I was a mac user before. One thing I really loved about Ubuntu was when I was compiling and running java programs for class my tab completion was really smart. When I needed to compile my class if I had a directory that looked like:


and I needed to compile the Client.java to take into account the most recent changes I would type:

javac C [TAB]

and it would complete to

javac Client.java

ignoring the .class files because you can't run javac on a .class. Also when I wanted to run the file typing

java C [TAB]

would result in

java Client

with no period. This was a very smart way of doing the tab completion that I got so used to that now it's driving me crazy when I hit tab and it gives me the Client. without actually completing to what I need it to be.

So is there any way to make the Mac bash completion smarter so that it would have this same effect?

2 Answers 2


*nix packages such as bash_completion can be installed with 3rd party package managers. I suggest Homebrew, but Fink and MacPorts also provide the bash_completion package. If it doesn't auto-handle the Java situation you describe, post back or read the man page.


I would suggest you set your default shell to zsh instead of bash. It comes bundled with Mac OS X and it's fully compatible with bash, but adds some nice features including much smarter tab completion.

Try it with chsh /bin/zsh

There's also a great framework for managing your zsh environment called oh-my-zsh. It's a great starting point for some powerful customization.

  • Interesting... never would have thought to completely change the shell. Won't this lose most of my current bash configurations as far as aliases and variable exports go? Dec 29, 2011 at 5:17
  • @CaldwellYSR Zsh is generally more powerful than bash (though bash can do the job too in this particular instance). Zsh isn't fully compatible with bash, so you'd lose some of your customizations. Aliases and variable exports can be copied, but other things like prompt settings would need to be redone. Dec 29, 2011 at 17:21
  • Not sure suggesting that the OP totally switch their setup is a reasonable suggestion.
    – josh
    Sep 21, 2016 at 14:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .