* Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1
[not found] <CAPXHQbPgepSFHX63F+Nt8TJ+znAaVqzzmSZmJqxj2mekhStO-g@mail.gmail.com>
@ 2011-11-10 2:46 ` Nathan Broadbent
2011-11-10 3:21 ` Junio C Hamano
0 siblings, 1 reply; 9+ messages in thread
From: Nathan Broadbent @ 2011-11-10 2:46 UTC (permalink / raw)
To: git
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:
-bash: [: 2: unary operator expected
Here is the related issue on github (the project is a set of git shortcuts):
https://github.com/ndbroadbent/scm_breeze/issues/11
Thanks for your time, I'd really appreciate some help!
Regards,
Nathan B
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1
2011-11-10 2:46 ` Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1 Nathan Broadbent
@ 2011-11-10 3:21 ` Junio C Hamano
2011-11-10 7:09 ` Johannes Sixt
[not found] ` <CAPXHQbP2O2C6sDVYLB=eMu0UpdMm79t3fqopqBvNpmdpKPRsXQ@mail.gmail.com>
0 siblings, 2 replies; 9+ messages in thread
From: Junio C Hamano @ 2011-11-10 3:21 UTC (permalink / raw)
To: nathan.f77; +Cc: git
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:
We have been cooking for 1.7.8 and have the first release candidate
1.7.8-rc1; could you try it and report what you find out?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1
2011-11-10 3:21 ` Junio C Hamano
@ 2011-11-10 7:09 ` Johannes Sixt
2011-11-10 8:52 ` Nathan Broadbent
[not found] ` <CAPXHQbP2O2C6sDVYLB=eMu0UpdMm79t3fqopqBvNpmdpKPRsXQ@mail.gmail.com>
1 sibling, 1 reply; 9+ messages in thread
From: Johannes Sixt @ 2011-11-10 7:09 UTC (permalink / raw)
To: nathan.f77; +Cc: Junio C Hamano, git
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:
>
> We have been cooking for 1.7.8 and have the first release candidate
> 1.7.8-rc1; could you try it and report what you find out?
It looks like _git_fetch is not meant to be called directly. All git
completions must go through _git.
See also this post:
http://thread.gmane.org/gmane.comp.version-control.msysgit/13310/focus=13335
-- Hannes
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1
2011-11-10 7:09 ` Johannes Sixt
@ 2011-11-10 8:52 ` Nathan Broadbent
2011-11-10 15:14 ` SZEDER Gábor
0 siblings, 1 reply; 9+ messages in thread
From: Nathan Broadbent @ 2011-11-10 8:52 UTC (permalink / raw)
To: Johannes Sixt; +Cc: Junio C Hamano, git
So, this is a feature, not a bug... Tab completion for aliases is
really useful. It's important enough to me that I won't stop until
I've found a solution.
I can appreciate that _git_fetch is not currently meant to be called
directly, but we found a way to utilize it when it previously worked.
Perhaps the scope of these completion functions could be expanded to
allow for aliases? I'll attempt to submit a patch if someone can give
me approval.
Thanks,
Nathan
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:
> >
> > We have been cooking for 1.7.8 and have the first release candidate
> > 1.7.8-rc1; could you try it and report what you find out?
>
> It looks like _git_fetch is not meant to be called directly. All git
> completions must go through _git.
>
> See also this post:
>
> http://thread.gmane.org/gmane.comp.version-control.msysgit/13310/focus=13335
>
> -- Hannes
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1
[not found] ` <CAPXHQbP2O2C6sDVYLB=eMu0UpdMm79t3fqopqBvNpmdpKPRsXQ@mail.gmail.com>
@ 2011-11-10 14:28 ` Nathan Broadbent
0 siblings, 0 replies; 9+ messages in thread
From: Nathan Broadbent @ 2011-11-10 14:28 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
> No change with 1.7.8-rc1, tab completion still fails
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1
2011-11-10 8:52 ` Nathan Broadbent
@ 2011-11-10 15:14 ` SZEDER Gábor
2011-11-12 8:08 ` Scott Bronson
0 siblings, 1 reply; 9+ messages in thread
From: SZEDER Gábor @ 2011-11-10 15:14 UTC (permalink / raw)
To: Nathan Broadbent; +Cc: Johannes Sixt, Junio C Hamano, git
Hi,
[Please don't top-post.]
> 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
I assume you have an
alias gf="git fetch"
somewhere, right?
> > >> 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,
2011-04-28), which was in v1.7.6. Since the clean-up in that commit
we only call _get_comp_words_by_ref() in the top-level completion
functions _git() and _gitk() to populate completion-related variables
($cur, $prev, $words, $cword), so invoking any _git_<cmd>() completion
function directly causes an error or wrong behavior, because all those
variables are empty.
Calling a completion function directly was not an issue earlier,
because every _git_<cmd>() completion function invoked
_get_comp_words_by_ref() to populate those variables, or in the
pre-_get_comp_words_by_ref() times they just accessed the
completion-related bash variables $COMP_WORDS and $COMP_CWORD
directly.
On Thu, Nov 10, 2011 at 04:52:33PM +0800, Nathan Broadbent wrote:
> So, this is a feature, not a bug... Tab completion for aliases is
> really useful. It's important enough to me that I won't stop until
> I've found a solution.
> I can appreciate that _git_fetch is not currently meant to be called
> directly, but we found a way to utilize it when it previously worked.
> Perhaps the scope of these completion functions could be expanded to
> allow for aliases? I'll attempt to submit a patch if someone can give
> me approval.
The quickest way would be to just revert da4902a7, but it would be the
dirtiest, too: it would bring back a lot of redundant calls to
_get_comp_words_by_ref() and it might have side-effects under zsh (but
I didn't think this through).
It would be a bit more clever to revert only parts of da4902a7, i.e.
to bring back _get_comp_words_by_ref() calls in _git_<cmd> completion
functions but not in __git_<whatever>() helper functions. This way
_git_<cmd>() functions would have their completion-related variables
initialized even when called directly instead through _git(), and
_get_comp_words_by_ref() would be called "only" twice during a single
completion. But that's still one too many, and again: there can be
issues with zsh.
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.
Best,
Gábor
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1
2011-11-10 15:14 ` SZEDER Gábor
@ 2011-11-12 8:08 ` Scott Bronson
2011-11-12 17:50 ` Scott Bronson
0 siblings, 1 reply; 9+ messages in thread
From: Scott Bronson @ 2011-11-12 8:08 UTC (permalink / raw)
To: SZEDER Gábor; +Cc: Nathan Broadbent, Johannes Sixt, Junio C Hamano, git
2011/11/10 SZEDER Gábor <szeder@ira.uka.de>
> > 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.
> 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. :)
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1
2011-11-12 8:08 ` Scott Bronson
@ 2011-11-12 17:50 ` Scott Bronson
2011-11-12 17:53 ` Nathan Broadbent
0 siblings, 1 reply; 9+ messages in thread
From: Scott Bronson @ 2011-11-12 17:50 UTC (permalink / raw)
To: SZEDER Gábor; +Cc: Nathan Broadbent, Johannes Sixt, Junio C Hamano, git
2011/11/12 Scott Bronson <bronson@rinspin.com>:
> 2011/11/10 SZEDER Gábor <szeder@ira.uka.de>
>> > 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,
>> ...
>> Alternatively, you could easily create your own wrapper function
>> around _git_fetch(), like this:
> Very true. But if you tweak the completion variables, you can fool
> _git_fetch into working perfectly:
> * If I had more time, I'd be tempted to write a function that
> would define all the wrapper functions.
I couldn't stop thinking about it last night, I had to try it. Here's the
result, seems to work great:
__define_git_completion () {
eval "
_git_$2_shortcut () {
COMP_LINE=\"git $2\${COMP_LINE#$1}\"
let COMP_POINT+=$((4+${#2}-${#1}))
COMP_WORDS=(git $2 \"\${COMP_WORDS[@]:1}\")
let COMP_CWORD+=1
local cur words cword prev
_get_comp_words_by_ref -n =: cur words cword prev
_git_$2
}
"
}
__git_shortcut () {
type _git_$2_shortcut &>/dev/null || __define_git_completion $1 $2
alias $1="git $2 $3"
complete -o default -o nospace -F _git_$2_shortcut $1
}
__git_shortcut ga add
__git_shortcut gb branch
__git_shortcut gba branch -a
__git_shortcut gco checkout
__git_shortcut gci commit -v
__git_shortcut gcia commit '-a -v'
__git_shortcut gd diff
__git_shortcut gdc diff --cached
__git_shortcut gds diff --stat
__git_shortcut gf fetch
__git_shortcut gl log
__git_shortcut glp log -p
__git_shortcut gls log --stat
On Github:
https://github.com/bronson/dotfiles/blob/731bfd951be68f395247982ba1fb745fbed2455c/.bashrc#L81
It would be nice to see the __define_git_completion function merged
upstram. Possible?
- Scott
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1
2011-11-12 17:50 ` Scott Bronson
@ 2011-11-12 17:53 ` Nathan Broadbent
0 siblings, 0 replies; 9+ messages in thread
From: Nathan Broadbent @ 2011-11-12 17:53 UTC (permalink / raw)
To: Scott Bronson; +Cc: SZEDER Gábor, Johannes Sixt, Junio C Hamano, git
2011/11/13 Scott Bronson <bronson@rinspin.com>
>
> 2011/11/12 Scott Bronson <bronson@rinspin.com>:
> > 2011/11/10 SZEDER Gábor <szeder@ira.uka.de>
> >> > 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,
> >> ...
> >> Alternatively, you could easily create your own wrapper function
> >> around _git_fetch(), like this:
> > Very true. But if you tweak the completion variables, you can fool
> > _git_fetch into working perfectly:
> > * If I had more time, I'd be tempted to write a function that
> > would define all the wrapper functions.
>
> I couldn't stop thinking about it last night, I had to try it. Here's the
> result, seems to work great:
>
>
> __define_git_completion () {
> eval "
> _git_$2_shortcut () {
> COMP_LINE=\"git $2\${COMP_LINE#$1}\"
> let COMP_POINT+=$((4+${#2}-${#1}))
> COMP_WORDS=(git $2 \"\${COMP_WORDS[@]:1}\")
> let COMP_CWORD+=1
>
> local cur words cword prev
> _get_comp_words_by_ref -n =: cur words cword prev
> _git_$2
> }
> "
> }
>
> __git_shortcut () {
> type _git_$2_shortcut &>/dev/null || __define_git_completion $1 $2
> alias $1="git $2 $3"
> complete -o default -o nospace -F _git_$2_shortcut $1
> }
>
> __git_shortcut ga add
> __git_shortcut gb branch
> __git_shortcut gba branch -a
> __git_shortcut gco checkout
> __git_shortcut gci commit -v
> __git_shortcut gcia commit '-a -v'
> __git_shortcut gd diff
> __git_shortcut gdc diff --cached
> __git_shortcut gds diff --stat
> __git_shortcut gf fetch
> __git_shortcut gl log
> __git_shortcut glp log -p
> __git_shortcut gls log --stat
>
>
> On Github:
> https://github.com/bronson/dotfiles/blob/731bfd951be68f395247982ba1fb745fbed2455c/.bashrc#L81
>
> It would be nice to see the __define_git_completion function merged
> upstram. Possible?
>
> - Scott
You are amazing!!! Thanks so much for this!
Nathan
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2011-11-12 17:53 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <CAPXHQbPgepSFHX63F+Nt8TJ+znAaVqzzmSZmJqxj2mekhStO-g@mail.gmail.com>
2011-11-10 2:46 ` Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1 Nathan Broadbent
2011-11-10 3:21 ` Junio C Hamano
2011-11-10 7:09 ` Johannes Sixt
2011-11-10 8:52 ` Nathan Broadbent
2011-11-10 15:14 ` SZEDER Gábor
2011-11-12 8:08 ` Scott Bronson
2011-11-12 17:50 ` Scott Bronson
2011-11-12 17:53 ` Nathan Broadbent
[not found] ` <CAPXHQbP2O2C6sDVYLB=eMu0UpdMm79t3fqopqBvNpmdpKPRsXQ@mail.gmail.com>
2011-11-10 14:28 ` Nathan Broadbent
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).