zsh补全资源?

发布于 2024-09-25 06:44:52 字数 484 浏览 1 评论 0原文

Zsh 补全是一个相当复杂的野兽,我发现手册页非常难以阅读,尤其是它缺少所有各种 optspec 形式等的(简单)示例。我自己还没有在网上找到任何内容,所以帮助是最受赞赏。

作为一个例子,这是我目前正在努力解决的问题,并且 zshcompsys 手册页没有提供任何说明。现在

#compdef mtt2

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

,当我输入 mtt2 时,我只提供 foobarbaz作为补全,为什么不使用 -h--help 等呢? 我需要向 _arguments 传递什么魔力才能获得所有可能性?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风轻花落早 2024-10-02 06:44:52

您需要开始用破折号完成的参数(我的意思是您输入要测试的参数,而不是 _arguments 参数)。您应该查看 zstyle,尝试传递 -h 和其他类似 :foobars: 的内容,甚至直接使用 compadd.示例:

  1. 直接使用 compadd:
    #compdef 测试
    A=( -h --help -V --version foo bar baz )
    compadd -a A
    
  2. 传递 -h 和其他内容,就像 :foobars: 一样:
    #compdef 测试
    A=( -h --help -V --version )
    _参数\
        - foobars \
        ':foobars:(foo bar baz)' \
        - 选项 \
        “:参数:($A)”
    
    或者
    
    A=( -h --help -V --version foo bar baz )
    _参数\
        “:::($A)”
    
  3. zstyle 控制完成样式。它在 man zshcompsys 的“完成系统配置”部分中进行了描述,并且可能有一个可以完成开关的选项,但我不知道哪个选项可以控制它。

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文