Re: [PATCH 10/12] completion: add new git_complete helper
- From
Felipe Contreras <felipe.contreras@gmail.com>
- Date
- Apr 11, 2012, 23:44 UTC
- Message-ID
- <CAMP44s3x0ruqP_N9FH=GKnzXMYtX_kUaLO77YKRGr2GmsA3LHg@mail.gmail.com>
- In-Reply-To
- <20120411225046.GU2289@goldbirke>
2012/4/12 SZEDER Gábor <szeder@ira.uka.de>:
Show 20 quoted lines
>> +{
>> + local name="${2-$1}"
>> + local cmd="${name#git_}"
>> + eval "$(typeset -f foo_wrap | sed -e "s/foo_cmd/$cmd/" -e "s/foo/_$name/")"
>> + complete -o bashdefault -o default -o nospace -F _${name}_wrap $1 2>/dev/null \
>> + || complete -o default -o nospace -F _${name}_wrap $1
>> +}
>> +
>> +git_complete git
>> +git_complete gitk
>
> Clever ;)
>
> But it needs a subshell and a sed invocation, so Windows people might
> not be all too happy about this. Perhaps it's not a big deal in the
> default case, because it will be done only twice at startup time.
> However, if someone wants several aliases on Windows, it can cause
> noticeable delay. It's a startup speed vs. convenience trade-off.
> Anyway, I don't have any ideas how those fork()s and exec() could be
> avoided.Well, if you look at the foo_wrap function you would notice there is not much 'foo' in it. We could have a __git_wrap () function instead, but we would need to find an alternative way to set the 'cmd' variable. The easiest would be to just don't set it at all. As I suggested, only __git_complete_remote_or_refspec needs it, and can be easily worked around.
-- Felipe Contreras