Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to have 2 different behavior of "tab" depending of the usage context.
I would like to have the default behavior of bind '"\t":complete' any time except when users are trying to complete arguments of the "mybashfunction" command. In this case I call a special function to generate the completion, but I would like "tab" to work like if bind '"\t":menu-complete' was set.

share|improve this question

I believe that its readline library will only support one kind of tab-completion behaviour at a time.

share|improve this answer

Is this what you're looking for?

share|improve this answer
Nope, that already what I have. I want complete for some command and menu-complete for some others – radius Aug 20 '09 at 0:38

You can achieve this by using bash complete rules ...

_myfunc() {
    _opts="zero one two"
    # COMPREPLY is bash built-in for array of possible completions
    # cur & prev are current & previous words typed in shell
    COMPREPLY=( $( compgen -W "${_opts}" -- ${cur} ))
    return 0
complete -F _myfunc myfunc

This won't touch bash's normal completion but when you tab complete myfunc you'll have "zero one two" as possible completions.

Edit: oh yeah, jam this into your bashrc or similar so it's sourced in new shells.

share|improve this answer
That's not what I want, I already have a custom completion function. What I would is to have <tab> acting as menu-complete when completing myfunc. But <tab> acting as complete in all others case. I have tried changing the binding inside _myfunc() but changing it inside the function is too late to have it working for the first <tab> (but works after but in this case I can't revert to complete) – radius Aug 20 '09 at 0:42

Your Answer


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.