From: Felipe Contreras <felipe.contreras@gmail.com>
To: "SZEDER Gábor" <szeder@ira.uka.de>
Cc: git@vger.kernel.org, Jonathan Nieder <jrnieder@gmail.com>,
Junio C Hamano <gitster@pobox.com>,
Thomas Rast <trast@student.ethz.ch>
Subject: Re: [PATCH v3] completion: add new _GIT_complete helper
Date: Sun, 6 May 2012 22:53:24 +0200 [thread overview]
Message-ID: <CAMP44s1bvez99p=hBreB4xDy9hRmwomYx8keae5Cj-mywdxjDQ@mail.gmail.com> (raw)
In-Reply-To: <20120506121204.GA5799@goldbirke>
On Sun, May 6, 2012 at 2:12 PM, SZEDER Gábor <szeder@ira.uka.de> wrote:
> Hi,
>
>
> On Sun, May 06, 2012 at 01:14:25PM +0200, SZEDER Gábor wrote:
>> On Sat, May 05, 2012 at 05:23:20PM +0200, Felipe Contreras wrote:
>> > +__git_func_wrap ()
>> > +{
>> > + if [[ -n ${ZSH_VERSION-} ]]; then
>> > + emulate -L bash
>> > + setopt KSH_TYPESET
>> > +
>> > + # workaround zsh's bug that leaves 'words' as a special
>> > + # variable in versions < 4.3.12
>> > + typeset -h words
>> > +
>> > + # workaround zsh's bug that quotes spaces in the COMPREPLY
>> > + # array if IFS doesn't contain spaces.
>> > + typeset -h IFS
>> > + fi
>> > + local cur words cword prev
>> > + _get_comp_words_by_ref -n =: cur words cword prev
>> > + __git_func "$@"
>> > +}
>> > +
>> > +_GIT_complete ()
>> > +{
>> > + local name="${2-$1}"
>> > + eval "$(typeset -f __git_func_wrap | sed -e "s/__git_func/_$name/")"
>>
>> Still don't like the subshell and sed here ...
>>
>> > + 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
>>
>> ... because it adds delay when the completion script is loaded. But I
>> still don't have ideas how to avoid them.
>
> Ok, I think I got it. How about this on top of Felipe's patch?
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index f300b87d..8c18db92 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -2688,19 +2688,19 @@ __git_func_wrap ()
> fi
> local cur words cword prev
> _get_comp_words_by_ref -n =: cur words cword prev
> - __git_func "$@"
> + $1
> }
>
> _GIT_complete ()
> {
> - local name="${2-$1}"
> - eval "$(typeset -f __git_func_wrap | sed -e "s/__git_func/_$name/")"
> - complete -o bashdefault -o default -o nospace -F _${name}_wrap $1 2>/dev/null \
> - || complete -o default -o nospace -F _${name}_wrap $1
> + local wrapper="__git_wrap_$1"
> + eval "$wrapper () { __git_func_wrap $2 ; }"
> + complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
> + || complete -o default -o nospace -F $wrapper $1
> }
This has unnecessary changes, and can be simplified this way:
diff --git a/contrib/completion/git-completion.bash
b/contrib/completion/git-completion.bash
index f300b87..dd1ff33 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2688,13 +2688,13 @@ __git_func_wrap ()
fi
local cur words cword prev
_get_comp_words_by_ref -n =: cur words cword prev
- __git_func "$@"
+ _$1
}
_GIT_complete ()
{
local name="${2-$1}"
- eval "$(typeset -f __git_func_wrap | sed -e "s/__git_func/_$name/")"
+ eval "_${name}_wrap () { __git_func_wrap $name ; }"
complete -o bashdefault -o default -o nospace -F _${name}_wrap
$1 2>/dev/null \
|| complete -o default -o nospace -F _${name}_wrap $1
}
Of course, it might make sense to use the $wrapper variable, but that
increases the diff, so I avoided it for reviewing purposes. And I
still see no point forcing users to specify the full name of the
function; they should not be bothered with such details.
Cheers.
--
Felipe Contreras
next prev parent reply other threads:[~2012-05-06 20:53 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-05 15:23 [PATCH v3] completion: add new _GIT_complete helper Felipe Contreras
2012-05-05 15:54 ` Jonathan Nieder
2012-05-05 16:38 ` Felipe Contreras
2012-05-05 16:47 ` Jonathan Nieder
2012-05-05 16:52 ` Jonathan Nieder
2012-05-05 17:20 ` Felipe Contreras
2012-05-05 17:33 ` Jonathan gives feedback --> flamewars inevitable? (Re: [PATCH v3] completion: add new _GIT_complete helper) Jonathan Nieder
2012-05-05 18:23 ` Felipe Contreras
2012-05-05 18:39 ` Jonathan gives feedback --> flamewars inevitable? Jonathan Nieder
2012-05-05 18:42 ` Jonathan Nieder
2012-05-06 5:23 ` Jonathan gives feedback --> flamewars inevitable? (Re: [PATCH v3] completion: add new _GIT_complete helper) Tay Ray Chuan
2012-05-14 9:11 ` Felipe Contreras
2012-05-05 17:44 ` [PATCH v3] completion: add new _GIT_complete helper Jonathan Nieder
2012-05-06 10:30 ` SZEDER Gábor
2012-05-06 20:47 ` Jonathan Nieder
2012-05-06 11:14 ` SZEDER Gábor
2012-05-06 11:30 ` SZEDER Gábor
2012-05-06 11:36 ` SZEDER Gábor
2012-05-06 12:12 ` SZEDER Gábor
2012-05-06 20:53 ` Felipe Contreras [this message]
2012-05-06 20:37 ` Felipe Contreras
2012-05-06 23:32 ` SZEDER Gábor
2012-05-07 0:20 ` Felipe Contreras
2012-05-07 9:22 ` SZEDER Gábor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAMP44s1bvez99p=hBreB4xDy9hRmwomYx8keae5Cj-mywdxjDQ@mail.gmail.com' \
--to=felipe.contreras@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=szeder@ira.uka.de \
--cc=trast@student.ethz.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).