Skip to content
Myr

[Fix] zsh: restore `nomatch` and `markdirs` rather than clobbering them

Before adoption: this commit came in with the history the project adopted, so no landing records it.

`unsetopt local_options nomatch` unsets both named options, so LOCAL_OPTIONS is off by the time the function returns and the `nomatch` change escapes into the caller's shell: one `nvm ls` or `nvm alias` leaves NO_MATCH off for the rest of the session, after which an unmatched glob is silently passed through as a literal. `setopt local_options nonomatch`, already used in `nvm_check_file_permissions`, restores on return. The `markdirs` line also cancelled the snapshot taken for `shwordsplit` on the line above it; that one is latent, as `nvm_ls` is only ever called inside a command substitution.

authored by Jordan Harband · committed by Jordan Harband · parent 3a72926 · Browse files · 2 files+56 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+56 added−2 removed

  • tests:+54 added−0 removed
  • other:+2 added−2 removed

2 files+56 added−2 removed

added:test/fast/Unit tests/zsh options survive nvm_list_aliases and nvm_ls+54 added
1#!/bin/sh23die () { echo "$@" ; cleanup ; exit 1; }45cleanup () {6 rm -rf "${TEST_DIR-}"7 unset TEST_DIR NVM_DIR8}910: nvm.sh11\. ../../../nvm.sh1213\. ../../common.sh1415# `local_options` is zsh-only, so no other shell can regress this16[ -n "${ZSH_VERSION-}" ] || exit 01718# an isolated NVM_DIR with a single known version, so that ambient versions19# and aliases can not affect any assertions. `alias/lts` is deliberately absent:20# globbing it is why `nvm_list_aliases` has to suppress `nomatch` at all.21TEST_DIR="${PWD}/nvm_zsh_options_tmp"22mkdir -p "${TEST_DIR}/alias" "${TEST_DIR}/versions/node/v24.13.0/bin" || die 'failed to create test dirs'23make_echo "${TEST_DIR}/versions/node/v24.13.0/bin/node" 'v24.13.0' || die 'failed to create test node binary'24echo '24' > "${TEST_DIR}/alias/default" || die 'failed to create default alias'25NVM_DIR="${TEST_DIR}"2627setopt nomatch28unsetopt markdirs29unsetopt shwordsplit3031nvm_list_aliases >/dev/null 2>&132[[ -o nomatch ]] || die 'nvm_list_aliases left nomatch unset'3334nvm alias >/dev/null 2>&135[[ -o nomatch ]] || die '"nvm alias" left nomatch unset'3637nvm ls >/dev/null 2>&138[[ -o nomatch ]] || die '"nvm ls" left nomatch unset'3940# called directly rather than in a command substitution, so that anything41# `nvm_ls` fails to restore is visible here42nvm_ls 24 >/dev/null 2>&143[[ -o markdirs ]] && die 'nvm_ls left markdirs set'44[[ -o shwordsplit ]] && die 'nvm_ls left shwordsplit set'4546# and the inverse: a caller that wants these on has to get them back47setopt markdirs48setopt shwordsplit4950nvm_ls 24 >/dev/null 2>&151[[ -o markdirs ]] || die 'nvm_ls left markdirs unset'52[[ -o shwordsplit ]] || die 'nvm_ls left shwordsplit unset'5354cleanup
modified:nvm.sh+2 added-2 removed
1387 unmodified lines
1388 if nvm_has_colors; then1389 NVM_HAS_COLORS=11390 fi13911392 nvm_is_zsh && unsetopt local_options nomatch1392 nvm_is_zsh && setopt local_options nonomatch1393 (1394 local ALIAS_PATH1395 for ALIAS_PATH in "${NVM_ALIAS_DIR}/${ALIAS}"*; do1396 NVM_NO_COLORS="${NVM_NO_COLORS-}" NVM_HAS_COLORS="${NVM_HAS_COLORS}" NVM_CURRENT="${NVM_CURRENT}" nvm_print_alias_path "${NVM_ALIAS_DIR}" "${ALIAS_PATH}" &
287 unmodified lines
1684 ;;1685 esac16861687 nvm_is_zsh && setopt local_options shwordsplit1688 nvm_is_zsh && unsetopt local_options markdirs1688 nvm_is_zsh && setopt local_options nomarkdirs16891690 local NVM_DIRS_TO_SEARCH11691 NVM_DIRS_TO_SEARCH1=''1692 local NVM_DIRS_TO_SEARCH2
3457 unmodified lines