Re: [PATCH] tcsh-completion re-using git-completion.bash

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

 



On Sat, Nov 17, 2012 at 6:15 PM, Marc Khouzam <marc.khouzam@xxxxxxxxx> wrote:
> On Fri, Nov 16, 2012 at 4:56 PM, Felipe Contreras
> <felipe.contreras@xxxxxxxxx> wrote:
>> On Fri, Nov 16, 2012 at 10:20 PM, Junio C Hamano <gitster@xxxxxxxxx> wrote:
>>
>>> The point is not about the quality of zsh's emulation
>>> of (k)sh when it is run under that mode, but is about not having to
>>> have that logic in bash-only part in the first place.
>>
>> As I said, that logic can be moved away _if_ my wrapper is merged. But
>> then again, that would cause regressions to existing users.
>
> Please forgive me as I don't know the background of the efforts for
> zsh git-completion or
> the syntax for zsh completion, but I thought I'd mention another
> approach I tried for tcsh
> which may work for zsh.
>
> I gather that using a wrapper for zsh causes concerns about
> backwards-compatibility.

I don't see any concerns.

> if [[ -n ${ZSH_VERSION-} ]]; then
>   # replace below by zsh completion commands calling `bash
> ${HOME}/.git-completion.bash`

>   complete git   'p/*/`bash ${HOME}/.git-completion.bash ${COMMAND_LINE}`/'
>   complete gitk 'p/*/`bash ${HOME}/.git-completion.bash ${COMMAND_LINE}`/'

That doesn't work in zsh. It might be possible to do something
similar, but it would probably require many more lines.

And we can achieve the same by essentially moving the relevant code of
my wrapper:

--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -23,10 +23,6 @@
 #    3) Consider changing your PS1 to also show the current branch,
 #       see git-prompt.sh for details.

-if [[ -n ${ZSH_VERSION-} ]]; then
-       autoload -U +X bashcompinit && bashcompinit
-fi
-
 case "$COMP_WORDBREAKS" in
 *:*) : great ;;
 *)   COMP_WORDBREAKS="$COMP_WORDBREAKS:"
@@ -2404,6 +2400,32 @@ __gitk_main ()
        __git_complete_revlist
 }

+if [[ -n ${ZSH_VERSION-} ]]; then
+       emulate -L zsh
+
+       __gitcompadd ()
+       {
+               compadd -Q -S "$4" -P "${(M)cur#*[=:]}" -p "$2" --
${=1} && _ret=0
+       }
+
+       _git ()
+       {
+               local _ret=1
+               () {
+                 emulate -L ksh
+                       local cur cword prev
+                       cur=${words[CURRENT-1]}
+                       prev=${words[CURRENT-2]}
+                       let cword=CURRENT-1
+                       __${service}_main
+               }
+               let _ret && _default -S '' && _ret=0
+               return _ret
+       }
+       compdef _git git gitk
+       return
+fi
+
 __git_func_wrap ()
 {
        if [[ -n ${ZSH_VERSION-} ]]; then

-- 
Felipe Contreras
--
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]