Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there any way to make BASH fill in the first match when I press TAB, kind of like the Windows command prompt?

(It should still display the list of matches, but it should cycle through them when I keep on pressing tab.)

i.e. the goal here is to be able to fill in any match with only the TAB key, given enough presses -- like in Windows.

share|improve this question

2 Answers 2

up vote 11 down vote accepted

Add the following to your .inputrc file, (exact location varies between systems):

"\C-i": menu-complete

This maps TAB to menu-complete, which auto-completes the first match.

Then add (or uncomment) show-all-if-ambiguous, this shows the list of possible completions on the first TAB press.

Alternatively, you can set menu-complete per session (without editing .inputrc) by doing

bind '"\C-i" menu-complete'
share|improve this answer
    
No. That's definitely nothing like the Windows command prompt. :-) –  Mehrdad Jul 19 '11 at 2:34
    
@Mehrdad: edited, I hope I got it now. –  Philomath Jul 19 '11 at 2:44
    
+1 almost!!! It's what I want, but is there any way to make it do that and display the menu if it's ambiguous? (It might be asking for too much, I know, but I'm hoping it's possible.) –  Mehrdad Jul 19 '11 at 2:50
    
@Mehrdad: if it's what you want, accept it, this helps people get the right answers fast. As for your new request to do both at once, I don't believe it's possible, but who knows?... You can however bind menu-complete to another key-sequence, like "\M-s" for Meta+S, so you can chose at will. –  Philomath Jul 19 '11 at 3:05
    
Well, the original version of my question kind of said "it should still display the list of matches", so what requested in the comment was nothing new -- it was already in the question. I just +1'd your answer because it got part of the question right. :-) –  Mehrdad Jul 19 '11 at 3:43

Though I don't know about getting this functionality to work with bash, zsh comes with set up with exactly what you want by default. Check out oh-my-zsh and zsh.

zsh has most of the features of bash with some added functionality out of the box, like the ability to navigate with only tab and enter!

Most linux distributions come with a package for installing zsh.

Hope this helps.

share|improve this answer
1  
... oh my zsh!! That's interesting, I'll take a look at it... it may or may not do what I need. –  Mehrdad Jul 19 '11 at 3:47
    
Glad I could help. What distribution are you using? I can give you a more in depth answer with a guide on how to install zsh and oh my zsh. –  Chris Knadler Jul 19 '11 at 3:48
    
+1 I installed zsh, it seems pretty awesome! If I don't run into any problems I might accept this too, thanks! :) (I'm using Ubuntu btw.) –  Mehrdad Jul 19 '11 at 3:55
    
Awesome, if you just ran apt-get install zsh and then ran the auto installer for oh-my-zsh here, you should be good to go. Let me know if you need any help setting it up. –  Chris Knadler Jul 19 '11 at 4:03

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.