nvm-sh / nvm

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

[BUG] `nvm` uses `most` even when `most` is not installed #3316

Closed madonuko closed 2 months ago

madonuko commented 2 months ago

Operating system and version:

nvm debug output:

```sh nvm --version: v0.39.7 $SHELL: /usr/bin/zsh $SHLVL: 1 whoami: 'mado' ${HOME}: /home/mado ${NVM_DIR}: '${HOME}/.nvm' ${PATH}: /home/windowsboy111/.local/share/pnpm:/opt:${HOME}/.nimble/bin:${HOME}/.cargo/bin:${HOME}/texlive:${HOME}/.local/bin:${HOME}/.local/bin:${HOME}/bin:${HOME}/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin $PREFIX: '' ${NPM_CONFIG_PREFIX}: '' $NVM_NODEJS_ORG_MIRROR: '' $NVM_IOJS_ORG_MIRROR: '' shell version: 'zsh 5.9 (x86_64-redhat-linux-gnu)' uname -a: 'Linux 6.6.14-200.fc39.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jan 26 20:12:16 UTC 2024 x86_64 GNU/Linux' checksum binary: 'sha256sum' OS version: Ultramarine Linux 39 (Atomic KDE Plasma Edition) awk: /usr/bin/awk, GNU Awk 5.2.2, API 3.2, PMA Avon 8-g1, (GNU MPFR 4.2.0-p12, GNU MP 6.2.1) curl: /usr/bin/curl, curl 8.2.1 (x86_64-redhat-linux-gnu) libcurl/8.2.1 OpenSSL/3.1.1 zlib/1.2.13 brotli/1.1.0 libidn2/2.3.7 libpsl/0.21.2 (+libidn2/2.3.4) libssh/0.10.6/openssl/zlib nghttp2/1.55.1 OpenLDAP/2.6.6 wget: /usr/bin/wget, GNU Wget 1.21.3 built on linux-gnu. git: /usr/bin/git, git version 2.43.0 ls: cannot access 'grep='\''egrep'$'\n''/usr/bin/egrep': No such file or directory grep: grep='egrep --color=auto' /usr/bin/egrep (egrep --color=auto), grep (GNU grep) 3.11 sed: /usr/bin/sed, sed (GNU sed) 4.8 cut: /usr/bin/cut, cut (GNU coreutils) 9.3 basename: /usr/bin/basename, basename (GNU coreutils) 9.3 ls: cannot access 'rm='\''rm'$'\n''/usr/bin/rm': No such file or directory rm: rm='rm --interactive=never' /usr/bin/rm (rm --interactive=never), rm (GNU coreutils) 9.3 ls: cannot access 'mkdir='\''nocorrect': No such file or directory mkdir: mkdir='nocorrect mkdir' (nocorrect mkdir), mkdir (GNU coreutils) 9.3 xargs: /usr/bin/xargs, xargs (GNU findutils) 4.9.0 nvm current: none which node: node not found which iojs: iojs not found which npm: npm not found npm config get prefix: nvm:271: command not found: npm npm root -g: nvm:271: command not found: npm ```

nvm ls output:

```sh N/A iojs -> N/A (default) node -> stable (-> N/A) (default) unstable -> N/A (default) ```

How did you install nvm?

Install script from README.

What steps did you perform?

  1. run nvm

What happened?

It seems to run the most pager which is not installed on my system. Seems to be a bad idea, not all distros include most, should use more (or less) instead.

Node Version Manager (v0.39.7)

Note: <version> refers to any version-like string nvm understands. This includes:
  - full or partial version numbers, starting with an optional "v" (0.10, v0.1.2, v1)
  - default (built-in) aliases: node, stable, unstable, iojs, system
  - custom aliases you define with `nvm alias foo`

 Any options that produce colorized output should respect the `--no-colors` option.

Usage:
  nvm --help                                  Show this message
    --no-colors                               Suppress colored output
  nvm --version                               Print out the installed version of nvm
  nvm install [<version>]                     Download and install a <version>. Uses .nvmrc if available and version is omitted.
   The following optional arguments, if provided, must appear directly after `nvm install`:
    -s                                        Skip binary download, install from source only.
    -b                                        Skip source download, install from binary only.
    --reinstall-packages-from=<version>       When installing, reinstall packages installed in <node|iojs|node version number>
    --lts                                     When installing, only select from LTS (long-term support) versions
    --lts=<LTS name>                          When installing, only select from versions for a specific LTS line
    --skip-default-packages                   When installing, skip the default-packages file if it exists
    --latest-npm                              After installing, attempt to upgrade to the latest working npm on the given node version
    --no-progress                             Disable the progress bar on any downloads
    --alias=<name>                            After installing, set the alias specified to the version specified. (same as: nvm alias <name> <version>)
    --default                                 After installing, set default alias to the version specified. (same as: nvm alias default <version>)
  nvm uninstall <version>                     Uninstall a version
  nvm uninstall --lts                         Uninstall using automatic LTS (long-term support) alias `lts/*`, if available.
  nvm uninstall --lts=<LTS name>              Uninstall using automatic alias for provided LTS line, if available.
  nvm use [<version>]                         Modify PATH to use <version>. Uses .nvmrc if available and version is omitted.
   The following optional arguments, if provided, must appear directly after `nvm use`:
    --silent                                  Silences stdout/stderr output
    --lts                                     Uses automatic LTS (long-term support) alias `lts/*`, if available.
    --lts=<LTS name>                          Uses automatic alias for provided LTS line, if available.
  nvm exec [<version>] [<command>]            Run <command> on <version>. Uses .nvmrc if available and version is omitted.
   The following optional arguments, if provided, must appear directly after `nvm exec`:
    --silent                                  Silences stdout/stderr output
    --lts                                     Uses automatic LTS (long-term support) alias `lts/*`, if available.
    --lts=<LTS name>                          Uses automatic alias for provided LTS line, if available.
  nvm run [<version>] [<args>]                Run `node` on <version> with <args> as arguments. Uses .nvmrc if available and version is omitted.
   The following optional arguments, if provided, must appear directly after `nvm run`:
    --silent                                  Silences stdout/stderr output
    --lts                                     Uses automatic LTS (long-term support) alias `lts/*`, if available.
    --lts=<LTS name>                          Uses automatic alias for provided LTS line, if available.
  nvm current                                 Display currently activated version of Node
  nvm ls [<version>]                          List installed versions, matching a given <version> if provided
    --no-colors                               Suppress colored output
    --no-alias                                Suppress `nvm alias` output
  nvm ls-remote [<version>]                   List remote versions available for install, matching a given <version> if provided
    --lts                                     When listing, only show LTS (long-term support) versions
    --lts=<LTS name>                          When listing, only show versions for a specific LTS line
    --no-colors                               Suppress colored output
  nvm version <version>                       Resolve the given description to a single local version
  nvm version-remote <version>                Resolve the given description to a single remote version
    --lts                                     When listing, only select from LTS (long-term support) versions
    --lts=<LTS name>                          When listing, only select from versions for a specific LTS line
  nvm deactivate                              Undo effects of `nvm` on current shell
    --silent                                  Silences stdout/stderr output
  nvm alias [<pattern>]                       Show all aliases beginning with <pattern>
    --no-colors                               Suppress colored output
  nvm alias <name> <version>                  Set an alias named <name> pointing to <version>
  nvm unalias <name>                          Deletes the alias named <name>
  nvm install-latest-npm                      Attempt to upgrade to the latest working `npm` on the current node version
  nvm reinstall-packages <version>            Reinstall global `npm` packages contained in <version> to current version
  nvm unload                                  Unload `nvm` from shell
  nvm which [current | <version>]             Display path to installed node version. Uses .nvmrc if available and version is omitted.
    --silent                                  Silences stdout/stderr output when a version is omitted
  nvm cache dir                               Display path to the cache directory for nvm
  nvm cache clear                             Empty cache directory for nvm
  nvm set-colors [<color codes>]              Set five text colors using format "yMeBg". Available when supported.
                                               Initial colors are:
                                                  bygre
                                               Color codes:
                                                r/R = red / bold red
Usage: grep [OPTION]... PATTERNS [FILE]...
Try 'grep --help' for more information.
Usage: grep [OPTION]... PATTERNS [FILE]...
Try 'grep --help' for more information.
                                                g/ = green / 
                                                b/B = blue / bold blue
                                                c/C = cyan / bold cyan
nvm:133: command not found: most
nvm:133: command not found: most
nvm:133: command not found: most
                                                m/ = magenta / 
                                                y/Y = yellow / bold yellow
                                                k/K = black / bold black
                                                e/W = light grey / white
Example:
  nvm install 8.0.0                     Install a specific version number
  nvm use 8.0                           Use the latest available 8.0.x release
  nvm run 6.10.3 app.js                 Run app.js using node 6.10.3
  nvm exec 4.8.3 node app.js            Run `node app.js` with the PATH pointing to node 4.8.3
  nvm alias default 8.1.0               Set default node version on a shell
  nvm alias default node                Always default to the latest available node version on a shell

  nvm install node                      Install the latest available version
  nvm use node                          Use the latest version
  nvm install --lts                     Install the latest LTS version
  nvm use --lts                         Use the latest LTS version

  nvm set-colors cgYmW                  Set text colors to cyan, green, bold yellow, magenta, and white

Note:
  to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)

What did you expect to happen?

Output without errors.

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

.zshrc:

export PATH=/opt:~/.nimble/bin:~/.cargo/bin:~/texlive:~/.local/bin:$PATH
export PATH="$PNPM_HOME:$PATH"
ljharb commented 2 months ago

nvm doesn't run any pager at all. however, i see you've aliased grep to egrep --color=auto', and rm to rm --interactive=never, and mkdir to nocorrect mkdir - so i suspect that perhaps there's some shell aliases you've set up that are causing issues.

madonuko commented 2 months ago

I thought nocorrect mkdir is a thing that zsh aliases to automatically? I've also checked my config files and grep most ~/.zshrc returns nothing…

ljharb commented 2 months ago

Maybe oh-my-zsh? zsh doesn't alias anything automatically.

The lines that are erroring about most are in the nvm_wrap_with_color_code function - so i suspect it's related to colorized output somehow.

Are you using global zsh aliases perhaps? Those are hugely problematic and might not be something nvm can work around.

madonuko commented 2 months ago

I guess it's an issue with OMZ:

/home/mado/.oh-my-zsh/plugins/common-aliases/common-aliases.plugin.zsh
7:alias la='ls -lAFh'   #long list,show almost all,show type,human readable
30:alias -g M="| most"

this is the output from rg most ~/.oh-my-zsh (truncated)

and in the file:

  25   │ # Command line head / tail shortcuts
  26   │ alias -g H='| head'
  27   │ alias -g T='| tail'
  28   │ alias -g G='| grep'
  29   │ alias -g L="| less"
  30   │ alias -g M="| most"
  31   │ alias -g LL="2>&1 | less"
  32   │ alias -g CA="2>&1 | cat -A"
  33   │ alias -g NE="2> /dev/null"
  34   │ alias -g NUL="> /dev/null 2>&1"
  35   │ alias -g P="2>&1| pygmentize -l pytb"

that seems to be the issue (maybe something using M)

ljharb commented 2 months ago

yup, that's exactly the issue. all of those global zsh aliases are impossible to avoid.

I'd suggest disabling omz entirely anyways, zsh folks tend to discourage it.

madonuko commented 2 months ago

I see, kinda dug into the code, adding single quotes around them doesn't even help at all, pretty surprising.

Anyway, thanks for looking into this.