Git tab completion in zsh throwing errors
Asked Answered
A

2

31

After struggling to get tab completion for git setup on osx, I've gotten some odd errors that I can't find the source too.

zsh:12: command not found: ___main
_default:compcall:12: can only be called from completion function

I'm not sure what is causing the error as everything is setup correctly.

zstyle ':completion:*:*:git:*' script ~/.git-completion.bash
autoload -U compinit && compinit
zmodload -i zsh/complist
source ~/.git-completion.zsh

Any ideas?

Almshouse answered 19/1, 2015 at 16:1 Comment(1)
The solution mentioned in this post worked for me unix.stackexchange.com/a/324516/483559Zondra
H
58

It seems that the git-completion.zsh is not designed to be sourceed. You could copy the git-completion.zsh file to somewhere in the $fpath and rename it to _git instead.

For example: (if you decide to have ~/.zsh/functions/_git.)

First, you could copy the git-completion.zsh to there and rename it to _git.

% mkdir -p ~/.zsh/functions && cp git-completion.zsh ~/.zsh/functions/_git

Then you could have your ~/.zshrc like this:

zstyle ':completion:*:*:git:*' script ~/.git-completion.bash
# `compinit` scans $fpath, so do this before calling it.
fpath=(~/.zsh/functions $fpath)
autoload -Uz compinit && compinit

If I'm not sure, I do rm ~/.zcompdump to make sure that compinit discards its cache.

Haywoodhayyim answered 20/1, 2015 at 0:32 Comment(7)
You don't need the zstyle part; by default it will use /usr/share/bash-completion/completions/git.Tetroxide
You literally just completed my 1hr search. Thanks! - The zstyle ':completion:*:*:git:*' script ~/.git-completion.bash is no longer neededSuckle
This results in __git_zsh_bash_func:8: command not found: __git_aliased_command for meUnplaced
got the same issue __git_zsh_bash_func:8: command not found: __git_aliased_command but the issue disappeared after restarting the terminal. also make sure the gitfast plugin disabled.Damiano
Im a little confused by the extensions. You mentioned git-completion.zsh and then in the .zshrc you have a dot bash file.Jory
@HernanPintos Both two files are necessary to use the completion scripts in the Git distribution: git.kernel.org/pub/scm/git/git.git/tree/contrib/… (We can see it by looking at git-completion.zsh, btw)Haywoodhayyim
One thing I had to add: compaudit | xargs chmod g-w to avoid the warning zsh compinit: insecure directories, run compaudit for list. https://mcmap.net/q/53898/-zsh-compinit-insecure-directories-closedCrony
T
8

pre

mkdir -p ~/.zsh
cd ~/.zsh

get completion scripts

curl -o git-completion.bash https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
curl -o _git https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.zsh

add to ~/.zshrc

# git completion
zstyle ':completion:*:*:git:*' script ~/.zsh/git-completion.bash
fpath=(~/.zsh $fpath)
autoload -Uz compinit && compinit

restart shell session

Tafoya answered 23/7, 2023 at 11:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.