zdharma-continuum / zinit

🌻 Flexible and fast ZSH plugin manager
MIT License
2.89k stars 125 forks source link

🐞 bug: `__git_zsh_bash_func:9: command not found: __git_aliased_command` when calling `zicompinit` #124

Closed paw-lu closed 2 years ago

paw-lu commented 2 years ago

Issue description

Any time I call zicompinit, git's completion gets polluted by errors.

% git com<TAB>
_git:.:42: no such file or directory:

% git commit<TAB>
% git commit __git_zsh_bash_func:9: command not found: __git_aliased_command
  git commit

git version 2.31.1

zinit config

# Zinit
# sh -c "$(curl -fsSL https://git.io/zinit-install)"
### Added by Zinit's installer
if [[ ! -f $HOME/.local/share/zinit/zinit.git/zinit.zsh ]]; then
    print -P "%F{33} %F{220}Installing %F{33}ZDHARMA-CONTINUUM%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f"
    command mkdir -p "$HOME/.local/share/zinit" && command chmod g-rwX "$HOME/.local/share/zinit"
    command git clone https://github.com/zdharma-continuum/zinit "$HOME/.local/share/zinit/zinit.git" && \
        print -P "%F{33} %F{34}Installation successful.%f%b" || \
        print -P "%F{160} The clone has failed.%f%b"
fi

source "$HOME/.local/share/zinit/zinit.git/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit

# Load a few important annexes, without Turbo
# (this is currently required for annexes)
zinit light-mode for \
    zdharma-continuum/zinit-annex-as-monitor \
    zdharma-continuum/zinit-annex-bin-gem-node \
    zdharma-continuum/zinit-annex-patch-dl \
    zdharma-continuum/zinit-annex-rust

# Plugins
# https://github.com/zdharma-continuum/fast-syntax-highlighting#zinit
zinit wait lucid light-mode for \
    atinit"ZINIT[COMPINIT_OPTS]=-C; zicompinit; zicdreplay" \
        zdharma-continuum/fast-syntax-highlighting

zinit version or commit ID

19347bad3b3a09f9b6344225ea338c63888eae70

zsh version

5.8

paw-lu commented 2 years ago

Not able to reproduce this on CentOS. But seems exlusive to my macos.

pschmitt commented 2 years ago

That's not a zinit issue. You are missing git completions. These are supposed to be shipped with zsh, but macOS doesn't. I don't know what's the recommended way of installing the missing comps on darwin. It's probably brew install something.

If you can't figure it out you can give zinit pack"rootless" for zsh-static a shot.

paw-lu commented 2 years ago

thanks for the responce!

You are missing git completions.

it definitley worked before migration to zinit

If I change my zshrc from the above to just

# My .zshrc
autoload -Uz compinit && compinit

git completions work as expected!

% git com<TAB>

% git commit

It's only when using zinit's zicompinit; where problems arise.

paw-lu commented 2 years ago

I see that if I run zinit completions that both needed files are present as well (_git and git-completion.bash)

% zinit completions | rg git
git                                                                %/opt/homebrew/share/zsh/site-functions

% ls /opt/homebrew/share/zsh/site-functions
_git git-completion.bash
pschmitt commented 2 years ago

This directory is probably not in your fpath.

zinit fpath -f /opt/homebrew/share/zsh/site-functions

I will add this my todo for the system-completions package, or zinit core. Not entirely sure where this would fit best yet.

paw-lu commented 2 years ago

yeah you're right—it isn't, and additing manually to fpath does solve the problem.

I guess the part I don't understand is why it was working fine before zinit, and zinit required more manual intervention. (Not actuall expecting support here since it's probably macos specific, just thinking outloud).

paw-lu commented 2 years ago

also (again), really appreciate the discussion and guidance here!

paw-lu commented 2 years ago

Looked into this a bit more—as the completion we got from this was worse than before for me (less options, not working on all commands, etc). The actual issue is that another file is being used for completion instead of the default completion provided by zsh.

No zinit, good completion

% autoload -Uz compinit && compinit

%  whence -v $_comps[git]
_git is a shell function from /usr/local/Cellar/zsh/5.8_1/share/zsh/functions/_git

With zinit, bad completion

% source "$HOME/.local/share/zinit/zinit.git/zinit.zsh"

% autoload -Uz compinit && compinit

% zinit completions | grep ^git,
100.0%
git, rg     %/opt/homebrew/share/zsh/site-functions

So we want the default /usr/local/Cellar/zsh/5.8_1/share/zsh/functions/_git, but zinit seems to prefer /opt/homebrew/share/zsh/site-functions, which is why the original exceptions were occuring.

What's the suggested method to giving priority here to /usr/local/Cellar/zsh/5.8_1/share/zsh/functions/_git over the homebrew directory?

paw-lu commented 2 years ago

To be clear, I know we can force /usr/local/Cellar/zsh/5.8_1/share/zsh/functions/_git by just running creinstall. Just wondering if there was a less hardcoded way to make sure this doesn't occur for other packages in the future.

zinit wait lucid light-mode for \
    ...
    atpull'zinit creinstall -q' \
        is-snippet /usr/local/Cellar/zsh/5.8_1/share/zsh/functions/_git \
    ...