Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] new completions for head and tail commands

On 2015/10/28, at 5:54, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Tue, Oct 27, 2015 at 1:34 PM, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
>> Jun T. wrote on Tue, Oct 27, 2015 at 22:44:47 +0900:
>>> +  opts='-A "-*"'
>>> (snip)
>>> +_arguments -C -s -S $opts : $args '*:file:_files' && return 0
>> Should that be ${=opts}?
> Or opts=(-A "-*") more likely.

I will commit/push with the fix opts=(-A "-*") (which I believe the
correct one). But there remains a behavior which I still don't understand.

Using opts=(-A "-*") is equivalent to
[1] _arguments  -A '-*'
while ${=opts} may correspond to
[2] _arguments  -A '"-*"'
i.e., the pattern includes double quotes. My original is equivalent to
[3] _arguments  '-A "-*"'
which looks quite wrong but seems to (accidentally) work due to a strange
option parsing of _arguments (so I didn't notice the error while testing).

All of the above work in the sense that, on non-gnu systems,

% tail file1 -<TAB>

does not complete any options. But if there is a file whose name starts
with a '-' (say, '-abc'), then [2][3] behave differently from [1].
With [2] or [3], the <TAB> completes the file name '-abc', while with [1]
nothing is offered (I get a message 'no more arguments' due to a setting
in my .zshrc). The same applies to

% tail -- -<TAB>

I'm not sure whether the behavior of [1] (not offering '-abc') is the
expected one or not, and have no idea why '-abc' is offered by [2][3].

Messages sorted by: Reverse Date, Date, Thread, Author