Terminal: Smart tab completion

Joined
May 9, 2011
Messages
98
Reaction score
2
Points
8
Location
Sewanee, TN
Your Mac's Specs
MacBook 13" 2.4 Intel Core 2 Duo 2 GB
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:
Code:
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:

Code:
javac C [TAB]

and it would complete to
Code:
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

Code:
java C [TAB]

would result in

Code:
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?
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
Hrm, I'd have to play with it. Ubuntu's method would drive me bananas.
 
OP
CaldwellYSR
Joined
May 9, 2011
Messages
98
Reaction score
2
Points
8
Location
Sewanee, TN
Your Mac's Specs
MacBook 13" 2.4 Intel Core 2 Duo 2 GB
I ended up getting bash-completion through homebrew and it works wonderfully :) thanks for the suggestion Dysfunction
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
I'm not familiar with the intricacies of configuring bash beyond changing the PS1 env variable to change my prompt so I may not be able to help much here. That said, I tested your situation and as expected, tab completion stopped at the . (so, Client.). This makes sense since there are multiple possibilities after the period. I'm not sure if it's possible to have bash ignore certain file extensions especially if you're only trying to do it for certain binaries (javac in this case). Let me take a look into this.

EDIT: I seem to be really slow on the typing today. Glad to see you found a solution.
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
I ended up getting bash-completion through homebrew and it works wonderfully :) thanks for the suggestion Dysfunction

Awesome! Glad it's working for you, nothing's worse than having to change how you work! (now I REALLY wish GNU grep had the -p option)
 
OP
CaldwellYSR
Joined
May 9, 2011
Messages
98
Reaction score
2
Points
8
Location
Sewanee, TN
Your Mac's Specs
MacBook 13" 2.4 Intel Core 2 Duo 2 GB
I'm not familiar with the intricacies of configuring bash beyond changing the PS1 env variable to change my prompt so I may not be able to help much here. That said, I tested your situation and as expected, tab completion stopped at the . (so, Client.). This makes sense since there are multiple possibilities after the period. I'm not sure if it's possible to have bash ignore certain file extensions especially if you're only trying to do it for certain binaries (javac in this case). Let me take a look into this.

EDIT: I seem to be really slow on the typing today. Glad to see you found a solution.

The bash-completion solution really extends the power of bash in my opinion. Not only because of the java problem I was having, but it also makes the tab completion ignore files when using the cd command (since you can't cd into a file) and ignore directories and other, uneditable files with nano or vim.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top