Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

With Bash auto-completion, is there a way to cycle through matches using menu-complete only if there are 1-2 options, and use listing with complete otherwise?

Example

home directory contains Desktop, Documents, Downloads, Projects and Public

~$ cd D<tab><tab> # lists matches
Desktop    Documents    Downloads
~$ cd De<tab> # completes Desktop

~$ cd P<tab> # completes Projects
~$ cd Projects<tab> # completes Public

The former is complete behavior, the latter is menu-complete. I want it to choose the second option if there are only 1-2 matches, the first if there are 3 or more.

share|improve this question
1  
This look like one of my question, seems impossible : serverfault.com/questions/41638/… –  radius Jul 31 '09 at 19:39
    
Indeed, it's similar to your question - though not quite the same. Either way, it should be possible by modifying the original completion script - but looking at /etc/bash_completion, I don't see any obvious hooks... –  AnC Aug 1 '09 at 7:04

2 Answers 2

It seems like there is no way.

I know you specifically asked for bash, but in case you want to give zsh a try, it uses ordinary list completion on the first press of tab, and cycles through the possible values on the second press. I think that is very convenient, and switching is a no-brainer as zsh is very similar to bash.

share|improve this answer
    
Yeah, I haven't made any progress either. There probably is a way, but it would require more familiarity with Bash's interals. As for zsh, ... well, I have no experience with it so far, and switching just for this one feature seems odd - but I might give it a try in a virtual machine. Thanks! –  AnC Aug 10 '09 at 10:13

Hit tab twice? Or are you trying to get something like a command then either arg1 or arg2 listed after the command?

ANSWER:

You'll want to edit your /etc/inputrc and add the following line somewhere:

"\C-i": menu-complete

Then run this command to immediately set your changes:

#: bind -f /etc/inputrc

Unfortunately, I don't see a way to limit it by the number of choices, but that is how you can switch it alternate as you hit the 'tab' key

Reference:independentchaos.com

share|improve this answer
    
When I hit tab twice, I get a choice of options - e.g. D<tab> lists Documents and Downloads. If there are only two options, I want the options to be cycled instead of listed. –  AnC Aug 10 '09 at 10:16
    
I think I found your answer. –  David Rickman Aug 11 '09 at 7:34
    
Thanks, but I'm afraid I already knew about menu-complete. I've clarified my original post with an example, hopefully that will help. –  AnC Aug 11 '09 at 17:28

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.