Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zsh completion resource?

Zsh completion is a rather complex beast, and I find the man-page very difficult to read, especially it's missing (simple) examples of all the various optspec forms etc. I haven't managed to find anything online myself yet so help would be most appreciated.

As an example here's what I'm struggling with at the moment, and the zshcompsys man-page doesn't offer any clarifications. I have

#compdef mtt2

_arguments -s : \
    '-h' '--help' \
    '-V' '--version' \
    ':foobars:(foo bar baz)'

Now, when I type mtt2 <TAB> I'm only offered foo, bar and baz as completions, why not -h, --help, etc, as well? What magic do I need to pass to _arguments in order to be offered all possibilities?

like image 288
Magnus Avatar asked Sep 26 '10 08:09

Magnus


2 Answers

You need to start argument that you complete with dash (I mean that argument that you type to test, not _arguments argument). You should either look at zstyle, try to pass -h and others just like :foobars: or even directly use compadd. Examples:

  1. Directly using compadd:
    #compdef test
    A=( -h --help -V --version foo bar baz )
    compadd -a A
    
  2. Passing -h and others just like :foobars::
    #compdef test
    A=( -h --help -V --version )
    _arguments \
        - foobars \
        ':foobars:(foo bar baz)' \
        - options \
        ":arguments:($A)"
    
    or
    A=( -h --help -V --version foo bar baz )
    _arguments \
        ":::($A)"
    
  3. zstyle controls completion style. It is described in «COMPLETION SYSTEM CONFIGURATION» section in man zshcompsys and probably has an option that will enable completing of switches, but I do not know which option controls that.
like image 170
ZyX Avatar answered Sep 27 '22 23:09

ZyX


I found this to be a good introduction: http://www.linux-mag.com/id/1106/

It's behind a login-wall, but you didn't specify...

like image 31
Michael Deardeuff Avatar answered Sep 27 '22 22:09

Michael Deardeuff