Repository: nvm
Issue: `nvm ls` outputs color codes when piped to another command
Labels: bugs,pull request wanted

<!-- Thank you for being interested in nvm! Please help us by filling out the following form if you‘re having trouble. If you have a feature request, or some other question, please feel free to clear out the form. Thanks! -->

#### Operating system and version: macOS 10.14.6 (18G8022)

#### `nvm debug` output:
<details>
<!-- do not delete the following blank line -->

```sh
nvm --version: v0.35.0
$TERM_PROGRAM: iTerm.app
$SHELL: /usr/local/bin/zsh
$SHLVL: 1
${HOME}: /Users/user
${NVM_DIR}: '${HOME}/.nvm'
${PATH}: ${HOME}/.nodenv/shims:${HOME}/.rbenv/shims:${HOME}/.rbenv/bin:${NVM_DIR}/versions/node/v16.0.0/bin:${HOME}/.rbenv/shims:${HOME}/bin:/usr/local/git/bin:/opt/local/bin:/opt/local/sbin:${HOME}/go/bin:/usr/local/sbin:/usr/local/bin:/usr/local/opt/gnu-sed/libexec/gnubin:/usr/local/opt/sqlite/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/mysql/bin:${HOME}/.composer/vendor/bin:/usr/local/opt/go/libexec/bin
$PREFIX: ''
${NPM_CONFIG_PREFIX}: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'zsh 5.8 (x86_64-apple-darwin18.7.0)'
uname -a: 'Darwin 18.7.0 Darwin Kernel Version 18.7.0: Tue Jan 12 22:04:47 PST 2021; root:xnu-4903.278.56~1/RELEASE_X86_64 x86_64'
OS version: Mac 10.14.6 18G8022
curl: /usr/bin/curl, curl 7.54.0 (x86_64-apple-darwin18.0) libcurl/7.54.0 LibreSSL/2.6.5 zlib/1.2.11 nghttp2/1.24.1
wget: not found
sed: /usr/local/opt/gnu-sed/libexec/gnubin/sed
cut: /usr/bin/cut
basename: /usr/bin/basename
rm: /bin/rm
mkdir: /bin/mkdir
xargs: /usr/bin/xargs
git: /usr/local/bin/git, git version 2.30.2
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 20070501
nvm current: system
which node: ${HOME}/.nodenv/shims/node
which iojs: iojs not found
which npm: ${HOME}/.nodenv/shims/npm
npm config get prefix: ${HOME}/.nodenv/versions/14.9.0
npm root -g: ${HOME}/.nodenv/versions/14.9.0/lib/node_modules

```
</details>

#### `nvm ls` output:
<details>
<!-- do not delete the following blank line -->

```sh
[0;34m        v16.0.0[0m
[0;32m->       system[0m
[0;34mdefault[0m [0;90m->[0m [0;34mv16.0.0[0m
[0;34mnode[0m [0;90m->[0m [0;34mstable[0m ([0;90m->[0m [0;34mv16.0.0[0m) [0;37m(default)[0m
[0;34mstable[0m [0;90m->[0m [0;34m16.0[0m ([0;90m->[0m [0;34mv16.0.0[0m) [0;37m(default)[0m
[1;31miojs[0m [0;90m->[0m [1;31mN/A[0m [0;37m(default)[0m
[1;31munstable[0m [0;90m->[0m [1;31mN/A[0m [0;37m(default)[0m
[1;33mlts/*[0m [0;90m->[0m [1;33mlts/fermium[0m ([0;90m->[0m [1;31mN/A[0m)
[1;33mlts/argon[0m [0;90m->[0m [1;31mv4.9.1[0m ([0;90m->[0m [1;31mN/A[0m)
[1;33mlts/boron[0m [0;90m->[0m [1;31mv6.17.1[0m ([0;90m->[0m [1;31mN/A[0m)
[1;33mlts/carbon[0m [0;90m->[0m [1;31mv8.17.0[0m ([0;90m->[0m [1;31mN/A[0m)
[1;33mlts/dubnium[0m [0;90m->[0m [1;31mv10.24.1[0m ([0;90m->[0m [1;31mN/A[0m)
[1;33mlts/erbium[0m [0;90m->[0m [1;31mv12.22.1[0m ([0;90m->[0m [1;31mN/A[0m)
[1;33mlts/fermium[0m [0;90m->[0m [1;31mv14.16.1[0m ([0;90m->[0m [1;31mN/A[0m)

```
</details>

#### How did you install `nvm`?
<!-- (e.g. install script in readme, Homebrew) -->
Homebrew

#### What steps did you perform?

* `nvm ls | pbcopy`
* Paste into a new issue

#### What happened?

All the ANSI codes were copied to the clipboard, as you can see from the section above.

#### What did you expect to happen?

`nvm ls` should omit ANSI colour codes and outputs plain text when being piped to another command. This is in line with how other colour-using commands work, so would be generally expected behaviour. Having to add `--no-colors` each time is a workaround, but it does not mirror the behaviour of other commands, which do the right thing automatically.

Perhaps the default behaviour could be to use colours when outputting to a TTY, and no colours when not outputting to a TTY, and adding a new `--colors` flag which could be used to force the issue when colours are required in a pipe?

#### Is there anything in any of your profile files that modifies the `PATH`?
<!--  (e.g. `.bashrc`, `.bash_profile`, `.zshrc`, etc) -->
Yes; they all execute after `eval "$(nodenv init -)"`, which is at the top of the file.