Thread (7 messages) flat view 7 messages, 5 authors, 2016-06-15

Re: Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1

From: Scott Bronson <hidden>
Date: 2016-06-15 22:52:28

2011/11/12 Scott Bronson [off-list ref]:
2011/11/10 SZEDER Gábor [off-list ref]
quoted
quoted
On Thu, Nov 10, 2011 at 3:09 PM, Johannes Sixt [off-list ref] wrote:
quoted
Am 11/10/2011 4:21, schrieb Junio C Hamano:
quoted
Nathan Broadbent [off-list ref] writes:
quoted
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help