Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

3 Answers 3

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? http://serverfault.com/questions/48671/bash-menu-complete-only-for-few-matches/52103#52103

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

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

 
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.