Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I've got auto-completion working for bash. When I type part of a program name, and then TAB, I get the full command. Works like expected, no complaints.

However on my setup I've got an alias defined called flexo (which logs me in to a machine with the same name). When I type fleTAB I only get flex, because that's a perfectly valid program on the machine. How do I instruct complete to ignore this specific completion? In other words I want fleTAB to complete to flexo and ignore flex completely. Thanks.

share|improve this question
    
Wouldn't it be a lot more straightforward to just change the alias to something unique - or shorter? –  jasonwryan May 5 '11 at 23:55
    
I think flexo is pretty concise, and no I'd rather keep my current scheme - type the name of the server, and off I go. –  Chris May 6 '11 at 2:47
add comment

1 Answer

up vote 2 down vote accepted

Monkeying with the algorithm for tab complete to rip a couple items out of the pool is more complicated than you imagine. It actually can be done but it's not easy, efficient to use or recommended.

Instead, @jasonwryan was on the right track that you should come up with something else for your command name. However instead of trying to stay with one word, the name of a server as a command name, I recommend you switch models to a multi word model like the rest of Unix. Tab completion for command names is quite different than tab completion for arguments, the latter is quite easy.

Setup a short easy alias like 's' or whatever your connect alias is, but don't include the host name. Then setup a custom completion routine for that command that ONLY autocompletes to host names like:

alias s=ssh
complete -F _known_hosts_real s

You could also create a custom function for this:

alias s=ssh
_my_hosts() {
    type compopt &>/dev/null && compopt -o nospace
    COMPREPLY=( $( compgen -S = -W 'flexo mexo dexo' -- "$cur") )
}
complete -F _my_hosts s
share|improve this answer
    
Hmm... that's very interesting. I'm not willing to give in that easily just yet. I'm going to spend some time hacking at this thing, even if it means (gasp) hacking the source code. Yes, I'm that bored :) If I can't figure out SOME way of doing this I'll accept yours as the answer. Thanks! –  Chris May 7 '11 at 14:34
add comment

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.