1

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.

2
  • 1
    Wouldn't it be a lot more straightforward to just change the alias to something unique - or shorter?
    – jasonwryan
    May 5, 2011 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. May 6, 2011 at 2:47

1 Answer 1

4

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
1
  • 2
    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! May 7, 2011 at 14:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .