nvm-sh / nvm

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions
MIT License
79.14k stars 7.92k forks source link

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

Open akefirad opened 3 years ago

akefirad commented 3 years ago

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.

ljharb commented 3 years ago

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?

akefirad commented 3 years ago

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.

tjx666 commented 2 years ago

@ljharb

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

image
ljharb commented 2 years ago

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

mdeguzis commented 4 months ago

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