Re: Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1
- From
- Scott Bronson <bronson@rinspin.com>
- Date
- Nov 12, 2011, 08:08 UTC
- Message-ID
- <CAKmUPx6TpbLL2GZq6G1nWPPBe=_SsqJmqXs1o9x5BxqR8y9h2Q@mail.gmail.com>
- In-Reply-To
- <20111110151412.GA11479@goldbirke>
2011/11/10 SZEDER Gábor <szeder@ira.uka.de>
Show 12 quoted lines
> > On Thu, Nov 10, 2011 at 3:09 PM, Johannes Sixt <j.sixt@viscovery.net> wrote: > > > Am 11/10/2011 4:21, schrieb Junio C Hamano: > > > > Nathan Broadbent <nathan.f77@gmail.com> writes: > > > >> Dear git mailing list, > > > >> I'm assigning the `_git_fetch` bash tab completion to the alias `gf`, > > > >> with the following command: > > > >> complete -o default -o nospace -F _git_fetch gf > > > >> The tab completion then works fine in git 1.7.0.4, but breaks on git > > > >> 1.7.7.1, with the following error: > > I didn't actually tried, but I guess this is a side-effect of da4902a7 > (completion: remove unnecessary _get_comp_words_by_ref() invocations,
I looked into it and this is exactly right.
Show 23 quoted lines
> Alternatively, you could easily create your own wrapper function
> around _git_fetch(), like this:
>
> _gf () {
> local cur prev words cword
> _get_comp_words_by_ref -n =: cur prev words cword
> _git_fetch
> }
>
>
> However.
>
> Having said all that, I'd like to point out that even if _git_fetch()
> didn't error out when called for the 'gf' alias, it still wouldn't
> work properly. After 'gf origin <TAB>' it offers the list of remotes
> again and it never offers refspecs, because it calls
> __git_complete_remote_or_refspec(), which
>
> - depends on the fact that there must be at least two words ('git'
> and 'fetch') on the command line before the remote, and
>
> - needs to know the git command (i.e. fetch, pull, or push) to offer
> the proper refspecs, but it can't find that out from your alias.Very true. But if you tweak the completion variables, you can fool _git_fetch into working perfectly:
_gf () {
COMP_LINE="git fetch${COMP_LINE#gf}"
let COMP_POINT+=7 # strlen('git fetch') - strlen('gf')
COMP_WORDS=(git fetch "${COMP_WORDS[@]:1}")
let COMP_CWORD+=1 local cur words cword prev
_get_comp_words_by_ref -n =: cur words cword prev
_git_fetch
}Can anyone find a place where this would fail?
It would be pretty easy to write similar wrappers for _git_add, _git_branch, and all the rest. [*]
Is there any possibility for a full set of wrappers (with better names) to be merged into the git completions? A number of peopl are disappointed that abbreviation completion doesn't work anymore, myself included: https://github.com/bobthecow/git-flow-completion/issues/2 https://github.com/ndbroadbent/scm_breeze/issues/11
I'm happy to write them if there's a chance they'd be merged. Thank you for all the work you've done on the completions Gábor!
- Scott
* If I had more time, I'd be tempted to write a function that would define all the wrapper functions.
define_wrapper add, ga
define_wrapper branch, gb
define_wrapper fetch, gf
...Nothing a little eval metaprogramming can't solve. :)