Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Are there shell versions that have a more intelligent tab completion?

I'd like to be able to type

cd foo-<TAB>

Then it would show me the possible completions along with numbers that I can type to select one of them:

cd foo-<TAB>
(1) foo-bar1  (2) foo-bar2  (3) foo-bad

So, after <TAB> I would type 3 and it would take me to foo-bad. Alternatively, using the arrow keys instead of typing the number would be fine.

share|improve this question

2 Answers 2

up vote 10 down vote accepted

You can enable menu-complete in Bash to step through the entries on the command line each time you press Tab. This is not really what you're looking for. If you want to try it, do this at the command prompt:

bind '"\C-i": menu-complete'

To make it persist, add this to your ~/.inputrc file:

"\C-i": menu-complete

Zsh has a feature that allows you to use the arrow keys to select an entry. Add this (or another variation) to your ~/.zshrc file:

zstyle ':completion:*' menu select=0

See man zshcompsys and search for "select=" (it will be in the section for the menu "Standard Style") for more information.

Otherwise, in Bash, you could write a function (or even create your own completion function) that would do something based on the select command. This is extremely simplistic:

$ select a in x y z; do cd $a; done
1) x
2) y
3) z
#?

You'd have to flesh that out a lot to get it to do what you want.

share|improve this answer
    
I like your select solution. That's exactly what I wanted! I added a break after cd $a, and I'll alias this command. That's way better than tab completion. –  dehmann Aug 4 '10 at 16:58
    
@dehman: It's part of "flesh that out". You need a break statement. Try: select a in x y z; do cd $a; break; done. You can use find to build the list of directories to choose from rather than hardcoding them. Another thing you might want to look into is the CDPATH variable (and here). –  Dennis Williamson Aug 4 '10 at 17:00

Do you already use normal completion? try

complete -d cd pushd rmdir

In your shell and see if it is close enough to what you want.

You can also try zsh which has better completion than bash.

share|improve this answer
2  
I was looking for a way to make autocomplete for cd exclude non-directories. This did it. You rock. –  Andy Jan 4 '12 at 23:01
    
@Andy check out bash_completion @ bash-completion.alioth.debian.org –  Rich Homolka Jan 6 '12 at 16:16

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.