【问题标题】:Completion: Multiple similar options完成:多个类似的选项
【发布时间】:2013-08-31 16:23:53
【问题描述】:

我想为一个将--with-PROG=--PROG-options 作为可选参数的程序编写完成。 PROG 可能是不同的程序之一。有许多不同的程序,所以我想避免为每个程序手动写出选项。我确实尝试了以下方法:

#compdef hello

typeset -A opt_args
local context state line

_hello()
{
    typeset -a PROGS
    PROGS=('gcc' 'make')
    _arguments \
        '--with-'${^PROGS}'[path to PROG]:executable:_files' \
        '--'${^PROGS}'-options[PROG options]:string:'
}

输出:

$ hello --gcc-options
--make-options  --gcc-options  -- PROG  options                                                                                                                          
--with-make     --with-gcc     -- path to PROG

但是,我希望将每个单独的选项放在单独的行上,并将PROG 替换为程序名称。最好的方法是什么?

【问题讨论】:

    标签: zsh zsh-completion


    【解决方案1】:

    您需要对_arguments 使用数组持有参数:

    _hello()
    {
        emulate -L zsh
        local -a args_args
        local prog
        for prog in gcc make ; do
            args_args+=( 
                "--with-${prog}[path to $prog]:executable:_files"
                "--${prog}-options[$prog options]:string:"
            )
        done
        _arguments $args_args
    }
    

    【讨论】:

      猜你喜欢
      • 2013-11-18
      • 2010-10-29
      • 2014-02-20
      • 2011-11-03
      • 1970-01-01
      • 1970-01-01
      • 2018-11-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多