autocomplete bash vs. zsh

Zsh completion does “matching” itself while bash expects you to filter completion candidates with, e.g. grep. “def” does not begin with “e” so it is not completed by default. You can think of the default matching as putting * at just the cursor position.

I assume you must be using bashcompinit for that example to have even come close to working in zsh. Unfortunately that means that the usual hooks for configuring zsh completions are not available. bashcompinit leaves zsh’s default matching active which as you observe makes it not behave in exactly the same way as bash – by using compadd’s -U option it could have done that. Zsh’s matching can usually be controlled with the matcher and matcher=list styles. Passing -M to compadd also works. The following is a basic native zsh completion similar to your bash example:

    _foo() { compadd -M 'l:|=*' abc def ghi }
    compdef _foo foo

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top