zdharma-continuum / zinit

🌻 Flexible and fast ZSH plugin manager
MIT License
3.18k stars 129 forks source link

[bug]: compdef is not defined after loading zinit #654

Open jankatins opened 6 months ago

jankatins commented 6 months ago

What happened?

I try to call compdef in an sourced alias file. According to https://github.com/zdharma-continuum/zinit?tab=readme-ov-file#calling-compinit-without-turbo-mode, compdef should be defined after sourcing zinit, but it isn't:

I'm using this code to load zinit (not sure where I got it from, it's ages since I installed zinit).

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

# This shows it's not there: compdef not found
which compdef
.zinit-tmp-subst-on
# And now it's there
which compdef && echo "compdef found"

Interestingly, it's also gone after my zinit calls, so I have to set it explicitly around souring the aliases:

# For some reason, comdef is not defined here and this makes it available, so aliases can use it
.zinit-tmp-subst-on
if [ -f ~/.zsh_aliases ]; then
    source ~/.zsh_aliases
fi
if [ -f ~/.zsh_aliases_local ]; then
    source ~/.zsh_aliases_local
fi
.zinit-tmp-subst-off

... in the last place of the file ...

# Load the real completion system
# Last to let aliases also define completions
autoload -Uz compinit
compinit
# Load completions which were intercepted by zinits fake compdef function
zinit cdreplay -q

Steps to reproduce

See zshrc code above

Relevant output

none

Screenshots and recordings

No response

Operating System & Version

OS: darwin21.3.0 | Vendor: apple | Machine: x86_64 | CPU: x86_64 | Processor: i386 | Hardware: x86_64

Zsh version

zsh 5.9 (x86_64-apple-darwin21.3.0)

Terminal emulator

xterm-256color (wezterm, nightly)

If using WSL on Windows, which version of WSL

None

Additional context

λ  zinit version
zinit v3.13.1-9-g8a219b8b (darwin21.3.0_x86_64)

Code of Conduct

svenjacobs commented 4 months ago

Same problem here. Interestingly I only see this error on macOS and not on Linux.

❯ zinit version
zinit v3.13.1-11-gd05a5301 (darwin21.3.0_arm64)

❯ zsh --version
zsh 5.9 (arm-apple-darwin21.3.0)
varp commented 2 weeks ago

Also experiencing the same issue

zinit v3.13.1-12-g0c471af3
zsh 5.9 (x86_64-apple-darwin23.0)