Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nvm enables zsh's nonomatch option globally #1937

Closed
agross opened this issue Nov 7, 2018 · 3 comments
Closed

nvm enables zsh's nonomatch option globally #1937

agross opened this issue Nov 7, 2018 · 3 comments
Labels
bugs Oh no, something's broken :-( pull request wanted This is a great way to contribute! Help us out :-D shell: zsh

Comments

@agross
Copy link
Contributor

agross commented Nov 7, 2018

  • Operating system and version: macOS

  • nvm debug output:

nvm debug
nvm --version: v0.33.11
$TERM_PROGRAM: iTerm.app
$SHELL: /usr/local/bin/zsh
$SHLVL: 1
$HOME: /Users/agross
$NVM_DIR: '$HOME/.nvm'
$PATH: $HOME/.rbenv/shims:$NVM_DIR/versions/node/v9.8.0/bin:$HOME/bin:$HOME/.dotfiles/vlc/bin:$HOME/.dotfiles/ruby/bin:$HOME/.dotfiles/macos/bin:$HOME/.dotfiles/homebrew/bin:/usr/local/Cellar/coreutils/8.30/libexec/gnubin:/usr/local/Cellar/make/4.2.1_1/libexec/gnubin:$HOME/.dotfiles/git/bin:$HOME/.dotfiles/fzf/bin:$HOME/.dotfiles/docker/bin:$HOME/.dotfiles/bin:$HOME/.cache/zplug/repos/zplug/zplug/bin:$HOME/.cache/zplug/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Wireshark.app/Contents/MacOS
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'zsh 5.6.2 (x86_64-apple-darwin18.0.0)'
uname -a: 'Darwin 18.2.0 Darwin Kernel Version 18.2.0: Fri Oct 5 19:41:49 PDT 2018; root:xnu-4903.221.2~2/RELEASE_X86_64 x86_64 i386 MacBookPro13,2 Darwin'
OS version: Mac 10.14.1 18B75
curl: /usr/local/bin/curl, curl 7.62.0 (x86_64-apple-darwin18.0.0) libcurl/7.62.0 SecureTransport zlib/1.2.11
wget: /usr/local/bin/wget, GNU Wget 1.19.5 built on darwin17.5.0.
git: /usr/local/bin/git, git version 2.19.1
grep: /usr/local/bin/grep, grep (GNU grep) 3.1
awk: /usr/local/bin/awk, GNU Awk 4.2.1, API: 2.0 (GNU MPFR 4.0.1, GNU MP 6.1.2)
sed: /usr/local/bin/sed, sed (GNU sed) 4.5
cut: /usr/local/Cellar/coreutils/8.30/libexec/gnubin/cut, cut (GNU coreutils) 8.30
basename: /usr/local/Cellar/coreutils/8.30/libexec/gnubin/basename, basename (GNU coreutils) 8.30
rm: /usr/local/Cellar/coreutils/8.30/libexec/gnubin/rm, rm (GNU coreutils) 8.30
mkdir: /usr/local/Cellar/coreutils/8.30/libexec/gnubin/mkdir, mkdir (GNU coreutils) 8.30
xargs: /usr/local/bin/xargs, xargs (GNU findutils) 4.6.0
nvm current: v9.8.0
which node: $NVM_DIR/versions/node/v9.8.0/bin/node
which iojs: iojs not found
which npm: $NVM_DIR/versions/node/v9.8.0/bin/npm
npm config get prefix: $NVM_DIR/versions/node/v9.8.0
npm root -g: $NVM_DIR/versions/node/v9.8.0/lib/node_modules
  • nvm ls output:
        v8.10.0
->       v9.8.0
default -> node (-> v9.8.0)
node -> stable (-> v9.8.0) (default)
stable -> 9.8 (-> v9.8.0) (default)
iojs -> N/A (default)
lts/* -> lts/carbon (-> v8.10.0)
lts/argon -> v4.8.7 (-> N/A)
lts/boron -> v6.13.1 (-> N/A)
lts/carbon -> v8.10.0
  • How did you install nvm?: Homebrew

  • What steps did you perform?

Sourced nvm.sh from my ~/.zshrc.

  • What happened?

setopt reports the nonomatch option is set.

  • What did you expect to happen?

setopt reports the nonomatch option is unset (or nomatch is set).

  • Is there anything in any of your profile files (.bashrc, .bash_profile, .zshrc, etc) that modifies the PATH?

Yes, but that is unrelated.

I can see why you added the check for the nomatch option in f9e14b7. By default zsh reports an error when you glob something that does not exist. The problem is that the way the option is enabled makes it the global default, regardless of user preference.

The zsh way would be to either add the N glob qualifier to the globs used in nvm_check_file_permissions, but that would yield to different behaviors on shells that do not support zsh glob qualifiers.

Another zsh-specific option is to use setopt local_options <some-option> to scope the option to the function.

@ljharb
Copy link
Member

ljharb commented Nov 7, 2018

The intention of the code (and similar patterns throughout nvm) is to ensure the option is set (or unset) as needed, and then restored to its original state, since zsh provides no other alternative to escape its disruptive options that's also posix-compatible as far as I'm aware.

However, in the commit you linked, it seems like i'm checking nonomatch, and then later, setting nomatch - which seems like a bug.

Perhaps a short-term fix is to correct the option name - but local_options is something i wasn't aware of, and using that throughout nvm seems like a much better approach, if viable.

@ljharb ljharb added shell: zsh bugs Oh no, something's broken :-( pull request wanted This is a great way to contribute! Help us out :-D labels Nov 7, 2018
@agross
Copy link
Contributor Author

agross commented Nov 7, 2018

After digging further, this is the line/commit that causes nonomatch to be set after my shell is done initializing:
3bb2634

@ljharb
Copy link
Member

ljharb commented Nov 7, 2018

wow, that's been there quite a long time.

I agree that unsetting the nomatch opt globally is a subpar side effect.

Perhaps a PR that removes that line, and switches everything to use local_options as needed, would take care of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugs Oh no, something's broken :-( pull request wanted This is a great way to contribute! Help us out :-D shell: zsh
Projects
None yet
Development

No branches or pull requests

2 participants