From: Felipe Contreras <hidden> Date: 2016-06-15 22:53:45
Hi,
In order to simplify the discussion I've cleaned up my patches related to
_GIT_complete, aliasing stuff, and such.
I'm only intending the firat patch for inclusion for now.
Cheers.
Felipe Contreras (6):
completion: add new __git_complete helper
tests: add more bash completion tests
completion: simplify _git_bundle
completion: simplify command stuff
completion: calculate argument position properly
completion: add public _GIT_complete helper
contrib/completion/git-completion.bash | 103 ++++++++++++++++----------------
t/t9902-completion.sh | 85 +++++++++++++++++++++++++-
2 files changed, 135 insertions(+), 53 deletions(-)
--
1.7.10
From: Felipe Contreras <hidden> Date: 2016-06-15 22:53:45
This simplifies the completions, and would make it easier to define
aliases in the future.
Signed-off-by: Felipe Contreras <redacted>
---
Since v3:
* Get rid of typeset and subshell
Since v2:
* Rename to _GIT_complete to follow bash completion "guidelines"
* Get rid of foo_wrap name
Since v1:
* Remove stuff related to aliases fixes; should work on top of master
contrib/completion/git-completion.bash | 69 +++++++++++++++-----------------
t/t9902-completion.sh | 2 +-
2 files changed, 33 insertions(+), 38 deletions(-)
@@ -2603,21 +2603,6 @@ _git (){localic=1command__git_dir-if[[-n${ZSH_VERSION-}]];then-emulate-Lbash-setoptKSH_TYPESET--# workaround zsh's bug that leaves 'words' as a special-# variable in versions < 4.3.12-typeset-hwords--# workaround zsh's bug that quotes spaces in the COMPREPLY-# array if IFS doesn't contain spaces.-typeset-hIFS-fi--localcurwordscwordprev-_get_comp_words_by_ref-n=:curwordscwordprevwhile[$c-lt$cword];doi="${words[c]}"case"$i"in
@@ -2667,22 +2652,6 @@ _git () _gitk(){-if[[-n${ZSH_VERSION-}]];then-emulate-Lbash-setoptKSH_TYPESET--# workaround zsh's bug that leaves 'words' as a special-# variable in versions < 4.3.12-typeset-hwords--# workaround zsh's bug that quotes spaces in the COMPREPLY-# array if IFS doesn't contain spaces.-typeset-hIFS-fi--localcurwordscwordprev-_get_comp_words_by_ref-n=:curwordscwordprev-__git_has_doubledash&&returnlocalg="$(__gitdir)"
@@ -2703,16 +2672,42 @@ _gitk ()__git_complete_revlist}-complete-obashdefault-odefault-onospace-F_gitgit2>/dev/null\-||complete-odefault-onospace-F_gitgit-complete-obashdefault-odefault-onospace-F_gitkgitk2>/dev/null\-||complete-odefault-onospace-F_gitkgitk+__git_func_wrap()+{+if[[-n${ZSH_VERSION-}]];then+emulate-Lbash+setoptKSH_TYPESET++# workaround zsh's bug that leaves 'words' as a special+# variable in versions < 4.3.12+typeset-hwords++# workaround zsh's bug that quotes spaces in the COMPREPLY+# array if IFS doesn't contain spaces.+typeset-hIFS+fi+localcurwordscwordprev+_get_comp_words_by_ref-n=:curwordscwordprev+_$1+}++# this is NOT a public function; use at your own risk+__git_complete()+{+localname="${2-$1}"+localwrapper="_${name}_wrap"+eval"$wrapper () { __git_func_wrap $name ; }"+complete-obashdefault-odefault-onospace-F$wrapper$12>/dev/null\+||complete-odefault-onospace-F$wrapper$1+}++__git_completegit+__git_completegitk# The following are necessary only for Cygwin, and only are needed# when the user has tab-completed the executable name and consequently# included the '.exe' suffix.#if[Cygwin="$(uname-o2>/dev/null)"];then-complete-obashdefault-odefault-onospace-F_gitgit.exe2>/dev/null\-||complete-odefault-onospace-F_gitgit.exe+__git_completegit.exegitfi
From: Felipe Contreras <hidden> Date: 2016-06-15 22:53:45
These tests try to excercise code that deals with 'words' and 'cword'.
Signed-off-by: Felipe Contreras <redacted>
---
t/t9902-completion.sh | 55 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
@@ -2695,8 +2696,7 @@ __git_func_wrap ()_$1}-# this is NOT a public function; use at your own risk-__git_complete()+_GIT_complete(){localname="${2-$1}"localwrapper="_${name}_wrap"
@@ -2705,13 +2705,13 @@ __git_complete ()||complete-odefault-onospace-F$wrapper$1}-__git_completegit-__git_completegitk+_GIT_completegit+_GIT_completegitk# The following are necessary only for Cygwin, and only are needed# when the user has tab-completed the executable name and consequently# included the '.exe' suffix.#if[Cygwin="$(uname-o2>/dev/null)"];then-__git_completegit.exegit+_GIT_completegit.exegitfi
From: Felipe Contreras <hidden> Date: 2016-06-15 22:53:45
No need to recalculate it.
Signed-off-by: Felipe Contreras <redacted>
---
contrib/completion/git-completion.bash | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
From: Felipe Contreras <hidden> Date: 2016-06-15 22:53:45
Positions are currently hard-coded, which means completions in the form
of 'git --foo bar' fail, because positions have been shifted.
This fixes the issue that was spotted in the mailing list regarding
certain aliases[1].
[1] http://thread.gmane.org/gmane.comp.version-control.git/185184
Cc: SZEDER Gábor <redacted>
Cc: Scott Bronson <redacted>
Cc: Nathan Broadbent <redacted>
Signed-off-by: Felipe Contreras <redacted>
---
contrib/completion/git-completion.bash | 16 +++++++++-------
t/t9902-completion.sh | 21 +++++++++++++++++++++
2 files changed, 30 insertions(+), 7 deletions(-)
From: SZEDER Gábor <hidden> Date: 2016-06-15 22:53:46
Hi,
On Mon, May 07, 2012 at 03:23:15AM +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
+ _$1
+}
+
+# this is NOT a public function; use at your own risk
+__git_complete ()
+{
+ local name="${2-$1}"
Please add the underscore prefix here right away, so we don't need
that "_$1" above in __git_func_wrap().
There is still no documentation about the parameters of
__git_complete(), so...
It seems to set up completion for the command given as first argument
to invoke the completion function given as second argument, right?
But the completion function argument is optional, and if it's not
specified, its name is derived from the command name by adding an
underscore prefix (in __git_func_wrap()). So, in case of 'git', $name
becomes 'git', hence the completion function to be invoked is _git().
So far so good.
+ local wrapper="_${name}_wrap"
But then the wrapper function becomes _git_wrap(). Uh, oh.
+ eval "$wrapper () { __git_func_wrap $name ; }"
... because this would then define the function _git_wrap(), which is
not good, because that's supposed to be the completion function for
the 'git wrap' command.
That's exactly why I wrote
local wrapper="__git_wrap_$1"
in my earlier post, and it was not an unnecessary change that could be
simplified away.
quoted hunk
+ complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
+ || complete -o default -o nospace -F $wrapper $1
+}
+
+__git_complete git
+__git_complete gitk
# The following are necessary only for Cygwin, and only are needed
# when the user has tab-completed the executable name and consequently
# included the '.exe' suffix.
#
if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
-complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
- || complete -o default -o nospace -F _git git.exe
+__git_complete git.exe git
fi
From: SZEDER Gábor <hidden> Date: 2016-06-15 22:53:46
Hi,
On Mon, May 07, 2012 at 03:23:18AM +0200, Felipe Contreras wrote:
No need to recalculate it.
Signed-off-by: Felipe Contreras <redacted>
---
contrib/completion/git-completion.bash | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
This seems to be the same patch you sent earlier as 7/12 in the first
round. I had a few comments back then, see
http://thread.gmane.org/gmane.comp.version-control.git/194958/focus=195276
But this $cmd variable will be only used in
__git_complete_remote_or_refspec(), so perhaps your idea later in that
thread about invoking it from _git_fetch() as
__git_complete_remote_or_refspec "fetch"
would be better. That would only require one modification in its four
callers, but neither in _git() in this patch nor in __git_complete()
later in the series to set $cmd.
Best,
Gábor