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.


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


Is this what you're looking for? Bash: menu-complete only for few matches

  • 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.

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.