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.

link|improve this question

67% accept rate
feedback

3 Answers

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

link|improve this answer
feedback

Is this what you're looking for? http://serverfault.com/questions/48671/bash-menu-complete-only-for-few-matches/52103#52103

link|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
feedback

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

_myfunc() {
    _opts="zero one two"
    # COMPREPLY is bash built-in for array of possible completions
    COMPREPLY=()
    # cur & prev are current & previous words typed in shell
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    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.

link|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
feedback

Your Answer

 
or
required, but never shown

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