I've noticed that for many of the commands I use in bash I have actually learned how many letters of the command I must type before I can press [TAB] to have bash successfully autocomplete the command. For example when opening chromium I dont usually type the whole command but instead type

$ chrom[TAB][ENTER]

and bash successfully autocompletes the command to chromium before I hit the [ENTER] key. Is there a way to make autocomplete work without having to hit [TAB]? My general thinking is that if I type

$ chrom[ENTER]

bash could check and see that chrom isnt a valid command, but it would make sense to autocomplete it to chromium since that is the only command that starts with chrom

I prefer having visual feedback which command I execute on the command line, which would be not possible with your suggested autocomplete function. If you want to shorten commonly used commands, you could consider creating an alias: alias chrom='chromium' That would even work if you happen to install a programe named chrome and correctly launch chromium.
–
MarcoJun 16 '12 at 12:54

2 Answers
2

This is only an idea, since I feel TAB isn't that hard to hit, muscle memory is an amazing thing.

But if we're going for maximum perverseness:

The BASH shell has a feature involving the 'command_not_found_handler' function, which often is used in many situations as a "Command Not Found" notifier, where it tells you where you might find more information on whatever you mistyped. This is often pre-installed in Ubuntu.

Of course, more information is easily found in the BASH Man Page, try searching for 'not_found'.

This could be beaten into submission and used to implement your 'tab-completion-on-fail^H^H^Henter' desire. Actual code is left as an exercise for the reader.

I fully agree with @Marco above, that I REALLY want the feedback from seeing/knowing what I typed and what I got are substantially similar.

You include this (and this code most likely already exists) in your .bashrc file with:

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

If you add them and want to see them immediately, either start a new shell session or run your .bashrc in your current terminal session, e.g. . ~/.bashrc or even just the aliases alone, . ~/.bash_aliases

This is better than the approach you initially outlined for a bunch of reasons and is the approach used by the community to give you this functionality.

I'm not sure that's really what the OP is asking for though. There's no autocompletion involved here, and you'd still have to remember the short commands.
–
slhck♦Jun 16 '12 at 14:07

Good point. I feel that although they aren't initially looking for this... this might be a good route to take. The OP may implement an answer that does auto-complete and presses [RETURN] and may then find that unintended commands get executed which can be hazardous. Think of delete link with no confirm, a well known problem. That experience may then lead the OP to 'want' to press return and may then like a short alias that will reduce their typing. Maybe! So I am giving information to try and help them going down that path.
–
Michael DurrantAug 10 '14 at 13:24