Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Bug: git completion: __git_ignore_line ignores complete branch
- X-seq: zsh-workers 35994
- From: Daniel Hahler <genml+zsh-workers@xxxxxxxxxx>
- To: Mikael Magnusson <mikachu@xxxxxxxxx>
- Subject: Re: Bug: git completion: __git_ignore_line ignores complete branch
- Date: Wed, 05 Aug 2015 21:22:27 +0200
- Cc: Zsh Hackers' List <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/simple; d=thequod.de; h= content-transfer-encoding:content-type:content-type:in-reply-to :references:subject:subject:mime-version:user-agent:from:from :date:date:message-id:received:received; s=postfix2; t= 1438802548; bh=XkeIhhMX//+k/kYIQOY2AU74p8WROFZBUwNnLGWMuLI=; b=N CRaszsXmaDYCsktEYnZPtx6C9FgKghsiEYh5mt6PxhM8Hv1aNYY/lK2zle4jtrEO qxu+sv7y0jA5x45oGIK0UheazAfAGHo3Gxm6AIGr/rJq8udxHvJczgS3Ma/7Txyc MnuHjlBDlN+tnHMstLm6gv7FuJFITi7xtfD4HB9w/Y=
- In-reply-to: <CAHYJk3SkYVj8CJ3PORdXobo_7-yx0wpNYVi=nkwJYweJ_TAjeA@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <55BE2CC6.5060104@thequod.de> <CAHYJk3SkYVj8CJ3PORdXobo_7-yx0wpNYVi=nkwJYweJ_TAjeA@mail.gmail.com>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 02.08.2015 18:20, Mikael Magnusson wrote:
> On Sun, Aug 2, 2015 at 4:44 PM, Daniel Hahler wrote:
>> __git_ignore_line_inside_arguments seems to be responsible for an error when trying
>> to complete an already complete branch.
>>
>> E.g. "git branch -D branch<tab>" results in:
>> -- no matches found: `branch-name' --
>>
>> But "git branch -D branc<tab>" will complete "branch".
>>
>> This is the function:
>>
>> (( $+functions[__git_ignore_line] )) ||
>> __git_ignore_line () {
>> declare -a ignored
>> ignored=()
>> ((CURRENT > 1)) &&
>> ignored+=(${line[1,CURRENT-1]//(#m)[\[\]()\\*?#<>~\^]/\\$MATCH})
>> ((CURRENT < $#line)) &&
>> ignored+=(${line[CURRENT+1,-1]//(#m)[\[\]()\\*?#<>~\^]/\\$MATCH})
>> $* -F ignored
>> }
>>
>> (( $+functions[__git_ignore_line_inside_arguments] )) ||
>> __git_ignore_line_inside_arguments () {
>> declare -a compadd_opts
>>
>> zparseopts -D -E -a compadd_opts V: J: 1 2 n f X: M: P: S: r: R: q F:
>>
>> __git_ignore_line $* $compadd_opts
>> }
>>
>> And it is used like this in _git-branch:
>>
>> dependent_deletion_args+='*: :__git_ignore_line_inside_arguments __git_branch_names'
>>
>> The problem is that it will ignore the current word, "branch", but should do so probably
>> only if it is not being completed currently, i.e. has a space at the end?!
>>
>> It works when completing "branc", because then only "branc" will be ignored.
>>
>> $line in the context of __git_ignore_line will be the part after "git branch -D", and $CURRENT will be 3. That seems to be off?!
>>
>> For the case at hand, using ${line[1,CURRENT-3]//...} seems to fix it, but probably
>> an index matching the position in $line, and then -1 should be used?!
>
> I haven't looked at the code but this sounds like huge confusion in
> the code. The ignore-line style already does this generically for
> anything you can complete, _git shouldn't be doing it manually in a
> single specific case at all.
I see, but it is not used (nor recommended to be used) by default (with "true" or "other).
Is it possible to use it dynamically, e.g. after "git branch -D" only?
The tag in this context appears to be ":completion::complete:git-branch::", which is not specific enough (for including the "-D"), but might make sense anyway?
zstyle ":completion::complete:git-branch:*" ignore-line true
A drawback of using this seems to be that it would also ignore branches named "branch" then..
Additionally, it won't work when using a function ("gb"), where completion is linked to via:
compdef _git gb=git-branch
But this can be fixed by using this instead:
compdef -e 'words=(git branch ${words[2,-1]}); ((CURRENT++)); _normal' gb
It seems like the special handling in _git makes sense, but could be generalized?!
Then it would have to use something else than $CURRENT, which refers to $words, while
it uses $line, which appears to be something shorter / more specific?!
And then the current word needs to be excluded, too.
Regards,
Daniel.
-----BEGIN PGP SIGNATURE-----
iEYEARECAAYFAlXCYnMACgkQfAK/hT/mPgBlLwCbB6aZ8Q0PeCkaA61/npf8ICXD
zjUAn0dhtRs3N50HuZ8hBdu6+AuuwYOi
=AFJT
-----END PGP SIGNATURE-----
Messages sorted by:
Reverse Date,
Date,
Thread,
Author