Repository: nvm
Issue: usage of `command` in `nvm.sh` does not prevent alias substitution for `alias -g` aliasses
Labels: shell: zsh,shell alias clobbering,pull request wanted

- Operating system and version:

Linux 4.18.16

zsh 5.6.2

- `nvm debug` output:
<details>
<!-- do not delete the following blank line -->

```sh
nvm --version: v0.33.11
$SHELL: /usr/bin/zsh
$SHLVL: 5
$HOME: /home/pseyfert
$NVM_DIR: '$HOME/.nvm_zsh'
$PATH: $HOME/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'zsh 5.6.2 (x86_64-pc-linux-gnu)'
uname -a: 'Linux 4.18.16-arch1-1-ARCH #1 SMP PREEMPT Sat Oct 20 22:06:45 UTC 2018 x86_64 GNU/Linux'
OS version: Arch Linux  ()
curl: /usr/bin/curl, curl 7.62.0 (x86_64-pc-linux-gnu) libcurl/7.62.0 OpenSSL/1.1.1 zlib/1.2.11 libidn2/2.0.5 libpsl/0.20.2 (+libidn2/2.0.4) libssh2/1.8.0 nghttp2/1.34.0
wget: /usr/bin/wget, GNU Wget 1.19.5 built on linux-gnu.
git: /usr/bin/git, git version 2.19.1
grep: grep is a global alias for grep GO, grep (GNU grep) 3.1
--color=always: not found
--exclude=*.pyc: not found
--exclude-dir=.git: not found
--exclude-dir=.svn: not found
-InH: not found
awk: /usr/bin/awk, GNU Awk 4.2.1, API: 2.0 (GNU MPFR 4.0.1, GNU MP 6.1.2)
sed: /usr/bin/sed, sed (GNU sed) 4.5
cut: /usr/bin/cut, cut (GNU coreutils) 8.30
basename: /usr/bin/basename, basename (GNU coreutils) 8.30
rm: /usr/bin/rm, rm (GNU coreutils) 8.30
mkdir: /usr/bin/mkdir, mkdir (GNU coreutils) 8.30
xargs: /usr/bin/xargs, xargs (GNU findutils) 4.6.0
nvm current: system
which node: /usr/bin/node
which iojs: iojs not found
which npm: /usr/bin/npm
npm config get prefix: /usr
npm root -g: /usr/lib/node_modules
```
</details>

- `nvm ls` output:
<details>
<!-- do not delete the following blank line -->

```sh
               
->       system
node -> stable (-> N/A) (default)
iojs -> N/A (default)
lts/* -> lts/dubnium (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.14.4 (-> N/A)
lts/carbon -> v8.12.0 (-> N/A)
lts/dubnium -> v10.13.0 (-> N/A)
```
</details>

- How did you install `nvm`? (e.g. install script in readme, Homebrew):

From [AUR](https://aur.archlinux.org/packages/nvm/)

- What steps did you perform?

```sh
export NVM_DIR="$HOME/.nvm_zsh"
source /usr/share/nvm/nvm.sh
source /usr/share/nvm/install-nvm-exec
NVM_VERSION_ONLY=true NVM_LTS=carbon nvm_remote_version ""
```

(Well, actually I tried `nvm install --lts=carbon`, but going through what nvm does when calling it like that leads here)

- What happened?

`nvm_remote_version` prints in magenta (is that the color's name?) `(standard`.
(I'm trying to attach a screenshot but the page says "Something went really wrong, and we can't process that file." … will try a different browser later to update)

- What did you expect to happen?

The same as in bash. It should've printed `v8.12.0` in black. (or rather the standard terminal color)

- Is there anything in any of your profile files (`.bashrc`, `.bash_profile`, `.zshrc`, etc) that modifies the `PATH`?

Yes, but these two lines are more relevant for this issue:

```zsh
#alias -g "GO"=$GREP_OPTIONS
#alias "grep"="grep $GREP_OPTIONS"
#GREP_OPTIONS="--color=always --exclude='*.pyc' --exclude-dir=.git --exclude-dir=.svn -InH"
alias -g "GO"="--color=always --exclude='*.pyc' --exclude-dir=.git --exclude-dir=.svn -InH"
alias -g "grep"="grep GO"
```

- What's your explanation for the problem?

nvm.sh defines the following shell function:

```sh
nvm_grep() {
  GREP_OPTIONS='' command grep "$@"
}
```

The `command` keyword should prevent shell alias substitution to take place. To
my understanding the mechanism is that the otherwise-to-be-resolved alias gets
moved out of the command-position. This is only effective for aliasses that do
not get resolved in non-command positions. Global zsh aliasses however also get
resolved in non-command positions (the use case being that filename and
linenumber printing remains aliassed when using `find -exec grep {} \;`).

Somewhere in the call stack of `nvm_remote_version`, a `nvm_grep` is run. This
calls for me the grep command still with the -InH flags and thus prints
`(standard input):<linenumber>:<expected output>`. Which is then cut off after
the first white space and `nvm install` tries to download the `(standard`
version of node instead of `v8.12.0`.

- Suggestions for fixing

Even global aliasses do not get resolved when quoted or backslashed:
```sh
  GREP_OPTIONS='' command 'grep' "$@"
  GREP_OPTIONS='' command \grep "$@"
```