From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10738 invoked by alias); 8 Oct 2014 14:40:43 -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: 33384 Received: (qmail 10238 invoked from network); 8 Oct 2014 14:40:39 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s1024; t=1412778908; bh=hmxVOtr9691cz3NIsd7yR+/Wxn2nS+YXlpPdveSCdj4=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:cc:In-reply-to:From:References:To:Subject:MIME-Version:Content-Type:Content-ID:Date:Message-ID; b=gfHvfbRec4+vn0SU3h+Z3a/SN9wmicFsp1ym5GoXtMdEY+a6R7//ql1FTsOiGRFzDaNFI2zIEOfOUf2pvibfZ0lFFk/T783nEm7ry6O3Nm+/unhkLI9AlP21BjDbSDG2+gRN7NXlcGJ9wRQGtQc/bAj8+oKug/sHxjfYfQFnqPg= X-Yahoo-Newman-Id: 635880.14037.bm@smtp128.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: RzSotVQVM1nqmMKL02rwAAK_LkK3d6qEg0Cdels.OCYo3IY Y.TlGKJ6aB_Ie_wT9IXNj.0f9mqqDlJzZqqPlvnfuVZXV27vi60L0cuXTamd YmPIn6FOTSEOWwBaWg9I7oHjwaf.5rh2VRSLIsVqgwjThkRcNA5523Zwm9hy YNgjYnB.kTfxqJMGIPcvQKusWp19JrES0BEbrD1wJI6o.VNL6dVLd4U2Bb0t pXi6b.CbufMiqTVsI85O6L9q6fPJFGMjgwreZyeFiw1M90Z_q.UPRCkgB7cz dAdLBhbKUWzhm5a4e3ocZIcVdZyb1_eCsTSm_G.s2xNFHtCRVJQKo0toNpqh 7ZW6CJcbrSK3ywIF2sSUrCiFxnRi4MLlk9Uv.sn_z0XCS3w1.035vAUiVcZi H_Lb7IGcbhMWyBycN24ljeNAkoQtBw3nUyFxaTXcFMsMbGlr0SMfFV8sc3WW dUktfVp7fP8qH9EUNt5GKzdNvZcBU2jOyE1GKsfTU9KLkLEqm7rU89z_HfPL I5c0lSsW7Kuri8iF7bLkTnxUsj6Axkw-- X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI- cc: zsh-workers@zsh.org In-reply-to: <20141008082016.GC1712@tarsus.local2> From: Oliver Kiddle References: <20141008082016.GC1712@tarsus.local2> To: Daniel Shahaf Subject: Re: [PATCH] Add xxd completion MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <30553.1412778907.1@thecus.kiddle.eu> Date: Wed, 08 Oct 2014 16:35:07 +0200 Message-ID: <30554.1412778907@thecus.kiddle.eu> Daniel Shahaf wrote: > Attached completion for xxd (a hex dump utility from Vim). It works, Great, thanks. > but I haven't written completion functions before so I might have > overlooked something. With that in mind, I've taken a look and have a couple of recommendations. > +local curcontext="$curcontext" ret=1 arguments None of these are actually needed. curcontext is only relevant if you call _arguments or _values with the -C option. You do use ret but a zsh function will pass on the return status of the last command it calls and _xxd only adds matches with a final call to _arguments. Finally the arguments array is only expanded once and could be specified inline at that point. > +# TODO: permit two hyphens (--autoskip, --groupsize, etc) Given that two dashes is accepted but not documented by xxd and that it also works for the short options, e.g. --u, I would just strip a dash as follows: [[ -prefix -- ]] && compset -P - > +# TODO: xxd - should show '-x' and '-x:' differently - give visual hint that there's a required argument Unless I'm missing something, there's nothing xxd specific in that desire. Perhaps it should be considered for the general case. In many cases, you can tell options that take an argument by the fact that the description starts with the word "specify". Taking -c as an example, you have: > + {-c+,-cols}'[output ARG octets per line]:number of octets per line' Until I checked, and found otherwise, I was guessing that the "ARG" came from a direct cut and paste from the -help output. The arguments to -c, -g, -l and -s also get in the way of completing -cols, -groupsize, -len and -seek: % xxd -grou number of octets per group option -groupsize To _arguments, the rou characters could be the number of octets. By using _guard, we can tell it that the number can only be the characters 0-9 (xxd allows hex so a few more characters are allowed there). With _guard, it looks like this: {-c+,-cols}'[specify number of octets per line]: :_guard "[0-9a-fA-Fx]#" "number of octets per line"' Oliver