From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4632 invoked by alias); 4 Aug 2015 18:58:00 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 35979 Received: (qmail 7839 invoked from network); 4 Aug 2015 18:57:57 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1438714673; bh=W4+Afo6mwXSnTzoIMFeH1jaU9pm2Ro9kHl/cQxD9xyw=; h=cc:In-reply-to:From:References:To:Subject:Date:From:Subject; b=koTDi8pVe9pak5s6OFCJw8wiUqe866f5XQRtE/myzhqO6mqxE6yyL22qmTp9DllIS7hLlNgpEX5q2bhEQEna2JR9xsla7JJH8BhCGw9KUjO7vmNBz9M9D7qiDhbXlRqOL1ts8xewHnySIf+Z0nR4fQhJc9FeotPoW7Yw2nuYH/h0i0t4kZTCk6R8PMbNe2MsLf++XFF7D93J9v+unNvl9dslTRgQ7nTM0rW4Pu1q76vKSz6KqsZUe2svoxbTWIosqxQihr5TV7/RFSKGIAxnphu+jCT+s2C3QH80wtCMh6m5mPXWMDJAfgezINESibZ+DANnOn+I4B+1la7y0kUKaA== X-Yahoo-Newman-Id: 540539.85427.bm@smtp139.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: vafB1.AVM1ny2e.RsUng7cYyEIEfNkjVtUay6wUVVjk8Hu9 wOtoEk5l2Jo5pWHnWM1HUh1WMODV1pwmQqe_mOFJJMgU3zwYZQcTNYL4wL_w Z5.6ywU4awJAWw5Xojd7t4YNUrnKIHFoIz.WYfk1e8HUKKSUPEE8kimDDEY8 BER5vuVmZlscpb.9y7RbNdEfzaBDXituVp3czoZhNq.eQIkM1Bk_EB7DGqBB .injOHUQo91ZC6G5c1HAwOqN7f3qL_h1pnuRgVck2sFcw75NAQFD0QXgJgeg kKu5BJW5UQpYMj2vCH8.qSoSBOUMmdeQqoUJQ_QAEd7jk689T50f14szcLhx ZFBQ_aAF52ysXytqBfH727ZUpTWrRxw01HXBgH9aOszxYijy6BEPRqEQ60E6 sMXkpcaRm9H6AOkJGz5g4aI7QK7AMNp8eT7ciXM4YUFyopsbFZ4gkPwC2ebE INkn7kxDgg0LmLqNPidBHF8sk.aG09Ia1oOXtiRvqxRhtP66iX4CNYdiER57 .bEmSmrtaWxDifKIjAMJWMan7.8g0uw-- X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI- cc: zsh-workers@zsh.org In-reply-to: From: Oliver Kiddle References: To: Will Leinweber Subject: Re: help with a completion script? MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1611.1438714672.1@thecus.kiddle.eu> Date: Tue, 04 Aug 2015 20:57:52 +0200 Message-ID: <1612.1438714672@thecus.kiddle.eu> Will Leinweber wrote: > The first argument to this binary is either one of several > subcommands, and that is all fine, however it can also be a *.cr file. > I tried adding in _files to the subcommand list, but instead of > showing files it shows just a literal * character and ends there. I'm not quite sure how you added _files to the subcommand list but that's a literal list while _files is a function. You need to call both _files and _describe. It sort-of works to just call them one after the other but it is better to use _alternative which allows things to be configured with zstyle and tag-order. You can use _alternative within _arguments directly and _arguments should probably be used for the --help and --version options. This comes out as: _arguments -C \ '(- 1 *)'{-h,--help}'[show help]' \ '(- 1 *)'{-v,--version}'[show version]' \ '1:sub-command: _alternative "subcommands:sub command:_crystal_commands" "files:file:_files -g \*.cr\(-.\)"' \ '*::arg:->cmd' && ret=0 The 1: _arguments entry is much the same as the (( CURRENT == 1 )) test. Other comments on the function: > _crystal() { ... > } > _crystal It isn't actually necessary to wrap the whole function with that. The function autoloading mechanism doesn't need it. Or, you might choose to only put this around the main part of the function after it defines all the other functions. > local context state line You don't actually need to make context local because you're passing -C to _arguments which uses curcontext instead. Unlike curcontext, context is an array and is only necessary if more than one state could be valid in the same situation. That's fairly rare and tends to only occur when there are optional arguments. > _call_function ret _crystal-$words[1] You're ignoring the result of this in the ret variable. It is common for functions to finish with: return ret. It is also wise to allow for the subcommand function not existing and fallback on the default (file) completion. For example: if ! _call_function ret _crystal_$words[1]; then _default && ret=0 fi > '(-D --define)'{-D,--define}'[Define a compile-time flag]:' The normal convention is for descriptions to be in all lowercase. You don't need to follow that of course. Also the explanation for the argument to -D is missing. If -D can be repeated, you can use \* instead of the '(-D --define)' exclusion list. You may also find that it can be --define= and perhaps -D+ (or other variations) depending on how the option can be separated from the argument. Crystal looks like an interesting project by the way. Oliver