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.


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'
  • 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
  • 1
    You know what? It seems like it's actually doing exactly what I want: First showing the menu, and then cycling through the options! I don't think I saw this on the first computer I tried (maybe I wasn't paying attention), but it seems to be working perfectly! :) (Edit: It seems like you need both this setting and show-all-if-ambiguous to be on for this to work.) – Mehrdad Jul 19 '11 at 15:58

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.

  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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