If I have several directories, like:

afoo abar

sometimes my terminal will refuse autocomplete when I press tab (e.g. "cd a" then tab), and print the list of directories instead. Sometimes it even throws a noisy, annoying sound. Any idea how to make it autocomplete in cases like this? E.g it can show abar first, and then afoo if I press tab again. I saw this is the case in windows, or some applciation in Ubuntu

share|improve this question

Something that is a life-saver for me is to have bash cycle through the possibilities instead of showing a dumb list.

As bash is using readline for its auto-completion, add the following lines to ~/.inputrc

Once you're satisfied and have tested thoroughly for a few days/weeks, move (don't copy!) the same settings from ~/.inputrc to /etc/inputrc which contains the system-wide settings, making this available to all users on your system (including guest).

# mappings for making up and down arrow searching through history:
"\e[A": history-search-backward
"\e[B": history-search-forward
"\e[C": forward-char
"\e[D": backward-char

#Use [Tab] and [Shift]+[Tab] to cycle through all the possible completions:
"\t": menu-complete
"\e[Z": menu-complete-backward

then exit your terminal and open it again...

Example: When you have 3 files: file1, file2 and file3 and you type:

e fTabTabTab

it'll cycle through:

e file1
e file2
e file3

and when you want to go back, just hit Shift+Tab

when you type:

very-complicated-command with lots of command line parameters

and next time you need the same command, you just type:

very

and it'll type for you:

very-complicated-command with lots of command line parameters

This will save you tons of time in bash! ;-)

share|improve this answer
1  
+1, interesting, but: 1. ~/.inputrc might be preferable over /etc/inputrc, and 2. I think you can set this in bash directly: unix.stackexchange.com/q/55203/70524, unix.stackexchange.com/a/16926/70524 – muru Apr 11 '15 at 7:45
1  
I used to work for Apple as a supplier and choose not to touch anything remotely Apple in my own time: it's an evil company. @AshleyCoolman! Try Ask Different. – Fabby Nov 17 '15 at 8:56
1  
A useful addition to this answer would be how to make <Shift-Tab> go backward in the cycle list – Enrico Maria De Angelis Jul 19 '16 at 14:50
1  
@EnricoMariaDeAngelis :D :D :D copy-paste error! (My system is set that way, and I didn't even notice! Thanks! ;-) – Fabby Jul 23 '16 at 11:37
1  
that this doesn't have more upvotes is a bigger upset than Taylor Swift winning the 2009 VMA over Beyonce – Brandon Dec 6 '16 at 17:33

After the 1st tab you need to insert more letters. So if you type

cd a

and hit tab you get nothing and after a second tab (immediately following) you get a list of the names starting with a and then need to insert an f to have it auto complete the remainder so

cd atabftab

will result in

cd afoo
share|improve this answer

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.