Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: _arguments: repeated option with multiple optargs
- X-seq: zsh-users 10742
 
- From: Roman Neuhauser <neuhauser@xxxxxxxxxx>
 
- To: zsh users <zsh-users@xxxxxxxxxx>
 
- Subject: Re: _arguments: repeated option with multiple optargs
 
- Date: Tue, 19 Sep 2006 13:19:17 +0000
 
- In-reply-to: <20060919014639.GB29030@xxxxxxxxxxxxxxxx>
 
- Mail-followup-to: zsh users <zsh-users@xxxxxxxxxx>
 
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
 
- References: <20060919014639.GB29030@xxxxxxxxxxxxxxxx>
 
# neuhauser@xxxxxxxxxx / 2006-09-19 01:46:39 +0000:
> Hello,
> 
> _arguments -s : '*-r=::->file:*:::->test'
> 
> does exactly what the manual say it does, IOW all the remaining words on
> the line are to be completed as described by the action. That's not what
> I want, though: the whole (-r file 1*test) can be repeated, and I'd like
> it to offer also -r.
> 
> Can _arguments do this for me somehow, or is this up to me?
    Thought I might be more specific.
    I have the following command (ABNF with implied whitespace at
    obvious places):
    cmdline = "tence" ["-h"] *("-i" dirlist) 1*("-r" file 1*(test))
    and this completion function:
    -------------------------
    #compdef tence
    local context line state
    typeset -A opt_args
    _arguments -s : \
        {-h,--help} \
        '*'{-i,--include-path}'=:include_path:->incpath' \
        '*'{-r,--run}'=:file:->testfile:*::class:->testclass'
    case $state in
    incpath)
        _dir_list && return 0
        ;;
    testfile)
        _files -g '*(.)' && return 0
        ;;
    testclass)
        # offer tests defined by this file for completion
        local -a tests
        tests=($(_call_program tests tence -C $words[1]))
        compadd "$@" -a tests && return 0
        ;;
    esac
    return 1
    -------------------------
    with "mycmd -r F a b c <CURSOR>" on the command line, completion
    should offer not only further tests (d e f), but "-r" as well.
    I don't want to pollute the interface with dummy arguments to halt
    the class optarg processing on, and also would love to defer as much
    as possible work to the standard functions.
    
    _arguments is already there, I don't want to write another parser.
-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE.             http://bash.org/?255991
Messages sorted by:
Reverse Date,
Date,
Thread,
Author