Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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:

Example.java
Example.class
Client.java
Client.class

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?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

*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.

share|improve this answer
    
This worked perfectly thank you sir –  CaldwellYSR Dec 29 '11 at 5:39

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.

share|improve this answer
    
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? –  CaldwellYSR Dec 29 '11 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. –  Gilles Dec 29 '11 at 17:21
    
Good to know. Thanks –  CaldwellYSR Dec 29 '11 at 17:24

Your Answer

 
discard

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.