zdharma-continuum / zinit

🌻 Flexible and fast ZSH plugin manager
MIT License
2.77k stars 123 forks source link

[bug]: No completions from plugins #511

Closed mustaqimM closed 1 year ago

mustaqimM commented 1 year ago

What happened?

Hello, with zinit freshly installed and no changes to .zshrc, I'm not getting any completions after running exec zsh or starting a new shell. If I install a plugin that has completions like starship by appending:

zinit ice as"command" from"gh-r" \
          atclone"./starship init zsh > init.zsh; ./starship completions zsh > _starship" \
          atpull"%atclone" src"init.zsh"
zinit light starship/starship

I get completions while in that shell, but with a new shell, I get no completions.

After installing a plugin with completions I get:

Installed 1 completions. They are stored in the $INSTALLED_COMPS array.

And running zinit completions show that it's installed.

EDIT. It seems if I manually run zinit compinit in a shell, then I get back completions.

Steps to reproduce

  1. Install zinit
  2. Install a plugin that has a completion file
  3. Reload shell
  4. No completion for that plugin when pressing TAB

Relevant output

No response

Screenshots and recordings

No response

Operating System & Version

OS: linux-gnu | Vendor: ubuntu | Machine: x86_64 | CPU: x86_64 | Processor: x86_64 | Hardware: x86_64

Zsh version

zsh 5.9 (x86_64-ubuntu-linux-gnu)

Terminal emulator

tmux-256color

If using WSL on Windows, which version of WSL

None

Additional context

Full .zshrc:

### 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

### End of Zinit's installer chunk

# Load starship theme
# line 1: `starship` binary as command, from github release
# line 2: starship setup at clone(create init.zsh, completion)
# line 3: pull behavior same as clone, source init.zsh
zinit ice as"command" from"gh-r" \
          atclone"./starship init zsh > init.zsh; ./starship completions zsh > _starship" \
          atpull"%atclone" src"init.zsh"
zinit light starship/starship

Code of Conduct

vladdoster commented 1 year ago

@mustaqimM,

This is a configuration issue and not a bug. Furthermore, it isn't related to zinit either, but how to use Zsh.

As you have observed, completions work when you run zinit compinit. If we look at the code for the compinit command, it runs the following code:

Screenshot 2023-04-30 at 17 46 28

It calls the .zinit-compinit function, so let us look at what it does. To do this, you can use the functions (it outputs a functions source code) command and run the following:

functions -x4 .zinit-compinit

I've highlighted the code essential to the issue at hand.

Screenshot 2023-04-30 at 17 53 40

In the Zsh documentation for completion, here is what compinit does.

This section describes the use of compinit to initialize completion for the current session when called directly; if you have run compinstall it will be called automatically from your .zshrc.

The issue is you don't initialize the completion system in your .zshrc. See the completions section in the README for this.

I'd recommend using turbo mode. All you need to do is add the following snippet to the end of your zshrc.

zi for \
    atload"zicompinit; zicdreplay" \
    blockf \
    lucid \
    wait \
  @zsh-users/zsh-completions