Skip to content

NVM installation resets completion logic of other commands #2489

@akefirad

Description

@akefirad

Operating system and version:

ProductName:	macOS
ProductVersion:	11.2.3
BuildVersion:	20D91

nvm debug output:

nvm --version: v0.38.0
$TERM_PROGRAM: iTerm.app
$SHELL: /bin/zsh
$SHLVL: 1
whoami: 'foo'
${HOME}: /Users/foo
${NVM_DIR}: '${HOME}/.nvm'
${PATH}: ${HOME}/.sdkman/candidates/maven/current/bin:${HOME}/.sdkman/candidates/java/current/bin:${HOME}/.sdkman/candidates/gradle/current/bin:${NVM_DIR}/versions/node/v15.14.0/bin:${HOME}/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/opt/fzf/bin
$PREFIX: ''
${NPM_CONFIG_PREFIX}: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'zsh 5.8 (x86_64-apple-darwin20.0)'
uname -a: 'Darwin 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64'
checksum binary: 'shasum'
OS version: macOS 11.2.3 20D91
curl: /usr/bin/curl, curl 7.64.1 (x86_64-apple-darwin20.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.41.0
wget: not found
sed: /usr/bin/sed
cut: /usr/bin/cut
basename: /usr/bin/basename
rm: /bin/rm
mkdir: /bin/mkdir
xargs: /usr/bin/xargs
git: /usr/bin/git, git version 2.24.3 (Apple Git-128)
ls: grep:: No such file or directory
grep: grep: aliased to grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox} (grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox}), grep (BSD grep) 2.5.1-FreeBSD
awk: /usr/bin/awk, awk version 20200816
nvm current: v15.14.0
which node: ${NVM_DIR}/versions/node/v15.14.0/bin/node
which iojs: iojs not found
which npm: ${NVM_DIR}/versions/node/v15.14.0/bin/npm
npm config get prefix: ${NVM_DIR}/versions/node/v15.14.0
npm notice
npm notice New minor version of npm available! 7.7.6 -> 7.10.0
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.10.0>
npm notice Run `npm install -g [email protected]` to update!
npm notice
npm root -g: ${NVM_DIR}/versions/node/v15.14.0/lib/node_modules

nvm ls output:

->     v15.14.0
default -> node (-> v15.14.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v15.14.0) (default)
stable -> 15.14 (-> v15.14.0) (default)
lts/* -> lts/fermium (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.1 (-> N/A)
lts/fermium -> v14.16.1 (-> N/A)

How did you install nvm?

Homebrew

What steps did you perform?

Tried to use the completion by pressing tab.

What happened?

No completion defined before NVM completion work!

What did you expect to happen?

To see the list of sub-commands

Is there anything in any of your profile files that modifies the PATH?

Just adding home/bin and local/bin to the path.

More Details

The whole issue started here DannyBen/alf#39. In my .zshrc, I'm sourcing ~/.bash_aliases before NVM completion script which contains:

if [[ -n ${ZSH_VERSION-} ]]; then
  autoload -U +X compinit && if [[ ${ZSH_DISABLE_COMPFIX-} = true ]]; then
    compinit -u
  else
    compinit
  fi
  autoload -U +X bashcompinit && bashcompinit
fi

The above also exists in NVM complection script as well. Now the issue is, according to @DannyBen's findings, the issue is that compinit should be called exactly once and before any call to complete, otherwise it resets the previous completion logic. (@DannyBen correct me if I'm wrong.)
Now, first, is our understanding correct? Second, what's the best solution to fix this issue?
Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions