1

The answers given in Disable auto-completion of remote branches in Zsh? no longer work, as zsh has changed the way it does this in the last six years.

I've hacked up a version of the __git_refs function which does not list remotes, and stored the definition in ~/.zsh-functions/__git_refs. The file starts with unfunction __git_refs 2> /dev/null to be sure the system function definition is removed.

If I source ~/.zsh-functions/__git_refs then type git checkout <Tab>, I see only local branches, which is correct.

But if I add source ~/.zsh-functions/__git_refs to the end of my .zshrc and launch a new zsh, I still get the system version of the function, and the completion shows remote branches as well as local ones.

How can I override this function without having to type source ~/.zsh-functions/__git_refs each time I launch a shell?

(Alternatively, is there a cleaner way of getting zsh to only show local branches in completions that still works on zsh 5.6.2?)

John Y
  • 1,161
  • 12
  • 23
  • There should be no difference, so I assume that, for ever reason, the function redefinition is not loaded. One reason could be that the new shell does not read .zshrc. Are you sure that it is started as interactive shell? Start the shell with tracing enabled (`-x`) to see what is going on. – user1934428 Jan 22 '19 at 07:25
  • One more point: The title of your post is misleading, because you are not overriding a _builtin_ function (zsh doesn't have any builtin function related to git), but just want to replace a function by a new definition. I would recommend against this practice, but of course you can do it, if you want. – user1934428 Jan 22 '19 at 07:32
  • Yup, it's started as an interactive shell and is sourcing the file as expected. The function seems to be installed by running `compinit -u`, which counts as builtin to me :) – John Y Jan 22 '19 at 13:39
  • The point is: If it works (as you said) when you _manually_ source your patches, and you have an interactive shell, the effect should be the same if you add the source-command for your patches as the last line in .zshrc. – user1934428 Jan 23 '19 at 07:56
  • I think something in oh-my-zsh might have overridden this, actually. I'll investigate further… – John Y Jan 23 '19 at 10:00

0 Answers0