nvm icon indicating copy to clipboard operation
nvm copied to clipboard

`compinit` (and `bashcompinit`) should not be called in the completion script for ZSH

Open akefirad opened this issue 4 years ago • 6 comments

This is an immediate followup on #2489. According to my finding (for example this by @marlonrichert), compinit and bashcompinit should not be called in completion scripts, but users should be instructed to add it manually to their .zshrc (if they have not done it already). The reason (as raised in the previous issue) is that compinit (and bashcompinit) must be called only once. Almost all completion scripts of real projects I found have done it this way (asking users to do it manually). Let me know what you think.

akefirad avatar Apr 21 '21 12:04 akefirad

oof, this sounds like both a large added cost (especially if #2489’s fix ensures it is called once), and is also a breaking change for zsh users. Would the same apply to bash?

ljharb avatar Apr 21 '21 13:04 ljharb

I'm not sure about bash TBH. Regarding the breaking change, yes, it kinda is, but not significant (it's not going to break any script or anything) IMHO. Up to you to decide, just wanted to let you know what I found.

akefirad avatar Apr 21 '21 14:04 akefirad

@ljharb

I's very strange that I'm using zsh but load bash completion:

image

tjx666 avatar Feb 20 '22 06:02 tjx666

@tjx666 despite its name, it works for both bash and zsh.

ljharb avatar Feb 20 '22 06:02 ljharb

Getting this error too despite my fpath:

   15 fpath=(
   16   /apollo/env/envImprovement/lib/zsh/${current_zsh_version}/zsh
   17   /usr/share/zsh/${current_zsh_version}/functions                                 
   18   /usr/share/zsh-completions
   19   /usr/share/zsh/site-functions
   20   /usr/lib64/zsh/${current_zsh_version}/zsh                                       
   21 )
~  22 echo "[INFO] Custom fpath is: $fpath"
+  23 
+  24 # Backwards compatibility for a few things such as: nvm
+  25 echo "[INFO] Loading bashcompinit and componit for ZSH"
+  26 autoload -Uz compinit && compinit
+  27 autoload -Uz bashcompinit && bashcompinit

mdeguzis avatar May 08 '24 16:05 mdeguzis