lukechilds / zsh-nvm

Zsh plugin for installing, updating and loading nvm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nvm completion not loading properly

mrmanc opened this issue · comments

When using this plugin (installed using antigen), and setting export NVM_COMPLETION=true, I don’t get proper completion when I type nvm <tab>. I get path based completion suggestions instead.

Zsh version: zsh 5.8 (x86_64-apple-darwin21.0)
MacOS version: 12.0.1
Macbook M1 Pro

I dug around in the code, and found that when I run the _zsh_nvm_completion function manually from my prompt, completion works fine (click to watch below recording). What is weird is when I edited the file to check that function was running, and sourcing $NVM_DIR/bash_completion successfully, I could see that it was.

  [[ -r $NVM_DIR/bash_completion ]] && source $NVM_DIR/bash_completion && echo "Successfully sourced bash completion"

asciicast

I took a look at $NVM_DIR/bash_completion to see what I could make out, and used set -x to get some debug. I can see that calling the function manually after opening a new shell seems to do a lot more. I’m not familiar enough with completion to understand where it’s going wrong. I can’t follow the complete:13 debug to see why nothing else runs. The call to complete on the last line of $NVM_DIR/bash_completion completes without error.

Here is the debug from opening a new shell:

+/Users/Mark.Crossfield/.nvm/bash_completion:6> command -v nvm
+/Users/Mark.Crossfield/.nvm/bash_completion:87> [[ -n 5.8 ]]
+/Users/Mark.Crossfield/.nvm/bash_completion:90> command -v compinit
+/Users/Mark.Crossfield/.nvm/bash_completion:97> autoload -U +X bashcompinit
+/Users/Mark.Crossfield/.nvm/bash_completion:97> bashcompinit
+bashcompinit:177> unfunction bashcompinit
+bashcompinit:178> autoload -Uz bashcompinit
+bashcompinit:179> return 0
+/Users/Mark.Crossfield/.nvm/bash_completion:100> complete -o default -F __nvm nvm
+complete:1> emulate -L zsh
+complete:2> local args void cmd print remove
+complete:3> args=( -o default -F __nvm nvm ) 
+complete:4> zparseopts -D -a void o: A: G: W: C: F: P: S: X: a b c d e f g j k u v 'p=print' 'r=remove'
+complete:6> [[ -n '' ]]
+complete:8> [[ -n '' ]]
+complete:13> compdef '_bash_complete -o default -F __nvm' nvm

And here’s the debug from calling the _zsh_nvm_completion function for comparison:

+/Users/Mark.Crossfield/.nvm/bash_completion:6> command -v nvm
+/Users/Mark.Crossfield/.nvm/bash_completion:87> [[ -n 5.8 ]]
+/Users/Mark.Crossfield/.nvm/bash_completion:90> command -v compinit
+/Users/Mark.Crossfield/.nvm/bash_completion:97> autoload -U +X bashcompinit
+/Users/Mark.Crossfield/.nvm/bash_completion:97> bashcompinit
+bashcompinit:177> unfunction bashcompinit
+bashcompinit:178> autoload -Uz bashcompinit
+bashcompinit:179> return 0
+/Users/Mark.Crossfield/.nvm/bash_completion:100> complete -o default -F __nvm nvm
+complete:1> emulate -L zsh
+complete:2> local args void cmd print remove
+complete:3> args=( -o default -F __nvm nvm ) 
+complete:4> zparseopts -D -a void o: A: G: W: C: F: P: S: X: a b c d e f g j k u v 'p=print' 'r=remove'
+complete:6> [[ -n '' ]]
+complete:8> [[ -n '' ]]
+complete:13> compdef '_bash_complete -o default -F __nvm' nvm
+compdef:1> local opt autol type func delete eval new i ret=0 cmd svc
+compdef:2> local -a match mbegin mend
+compdef:4> emulate -L zsh
+compdef:5> setopt extendedglob
+compdef:9> ((  ! 2  ))
+compdef:14> getopts anpPkKde opt
+compdef:38> shift OPTIND-1
+compdef:40> ((  ! 2  ))
+compdef:45> [[ -z '' ]]
+compdef:49> [[ -z '' ]]
+compdef:49> [[ '_bash_complete -o default -F __nvm' = *=* ]]
+compdef:79> func='_bash_complete -o default -F __nvm' 
+compdef:80> [[ -n '' ]]
+compdef:81> shift
+compdef:83> case  (widgetkey)
+compdef:83> case  (key)
+compdef:83> case  (*)
+compdef:131> ((  1  ))
+compdef:132> [[ nvm = -N ]]
+compdef:134> [[ nvm = -p ]]
+compdef:136> [[ nvm = -P ]]
+compdef:139> case  (pattern)
+compdef:139> case  (postpattern)
+compdef:139> case  (*)
+compdef:155> [[ nvm = *=* ]]
+compdef:159> cmd=nvm 
+compdef:160> svc='' 
+compdef:162> [[ -z '' ]]
+compdef:163> _comps[$cmd]='_bash_complete -o default -F __nvm' 
+compdef:164> [[ -n '' ]]
+compdef:169> shift
+compdef:131> ((  0  ))

Same here 😟

same here, macbook with m1

same here :-(
Cannot get zsh completion working even when calling the _zsh_nvm_completion function manually