Re: [PATCH] tcsh-completion re-using git-completion.bash
- From
Marc Khouzam <marc.khouzam@gmail.com>
- Date
- Nov 17, 2012, 17:15 UTC
- Message-ID
- <CAFj1UpFbuHVhPOQVB9-sPjW2aBN=H+OUyYnz00qASZ5ssbwmGw@mail.gmail.com>
- In-Reply-To
- <CAMP44s0y3UPVT+ndELaKNsWXAPG3kv-Xq_Wf6ONDF3Z99A5zMQ@mail.gmail.com>
On Fri, Nov 16, 2012 at 4:56 PM, Felipe Contreras <felipe.contreras@gmail.com> wrote:
Show 8 quoted lines
> On Fri, Nov 16, 2012 at 10:20 PM, Junio C Hamano <gitster@pobox.com> 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. So, what could be done is have the bash script do both jobs: setup the zsh completion commands, and output the git completion using bash itself. At the top of git-completion.bash (or it could be even pushed at the bottom using if/else) we could use:
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}`/'
exit
fiThat way the zsh user would still simply do 'source ~/.git-completion.bash' which would only execute the two zsh completion setup commands. Then, when completion is triggered, it calls `bash ${HOME}/.git-completion.bash ${COMMAND_LINE}` and processes the output like tcsh does. This limits the zsh-specific code to 2 lines for the entire script.
I got this to work for tcsh (solution (B)) adding the following a the top of git-completion.bash:
test "$tcsh" != "" && \
complete git 'p,*,`${HOME}/.git-completion.sh
"${COMMAND_LINE}"|\sort|\uniq`,' && \
complete gitk 'p,*,`${HOME}/.git-completion.sh
"${COMMAND_LINE}"|\sort|\uniq`,' && \
exitbut I didn't think people would go for that since those lines have to work in both bash and tcsh syntax. I thought this made the script a bit brittle.
Just a thought.
Marc