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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2011/11/12 Scott Bronson <bronson@xxxxxxxxxxx>:
> 2011/11/10 SZEDER Gábor <szeder@xxxxxxxxxx>
>> > On Thu, Nov 10, 2011 at 3:09 PM, Johannes Sixt <j.sixt@xxxxxxxxxxxxx> wrote:
>> > > Am 11/10/2011 4:21, schrieb Junio C Hamano:
>> > > > Nathan Broadbent <nathan.f77@xxxxxxxxx> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]