[Fix] Allow zsh users to have the nomatch option set

Closes #1937.
Alexander Groß 2018-11-08 00:55:52 +01:00 committed by Jordan Harband
parent f3fd5eff46
commit 17586b971a
No known key found for this signature in database
GPG Key ID: 64A196AEE0916D55
1 changed files with 15 additions and 94 deletions

109
nvm.sh
View File

@ -12,6 +12,10 @@
NVM_SCRIPT_SOURCE="$_" NVM_SCRIPT_SOURCE="$_"
nvm_is_zsh() {
[ -n "${ZSH_VERSION-}" ]
}
nvm_echo() { nvm_echo() {
command printf %s\\n "$*" 2>/dev/null command printf %s\\n "$*" 2>/dev/null
} }
@ -243,8 +247,7 @@ nvm_install_latest_npm() {
if [ -z "${NVM_CD_FLAGS-}" ]; then if [ -z "${NVM_CD_FLAGS-}" ]; then
export NVM_CD_FLAGS='' export NVM_CD_FLAGS=''
fi fi
if nvm_has "unsetopt"; then if nvm_is_zsh; then
unsetopt nomatch 2>/dev/null
NVM_CD_FLAGS="-q" NVM_CD_FLAGS="-q"
fi fi
@ -1017,12 +1020,7 @@ nvm_ls() {
;; ;;
esac esac
local ZSH_HAS_SHWORDSPLIT_UNSET nvm_is_zsh && setopt local_options shwordsplit
ZSH_HAS_SHWORDSPLIT_UNSET=1
if nvm_has "setopt"; then
ZSH_HAS_SHWORDSPLIT_UNSET="$(set +e ; setopt | nvm_grep -q shwordsplit ; nvm_echo $?)"
setopt shwordsplit
fi
local NVM_DIRS_TO_SEARCH1 local NVM_DIRS_TO_SEARCH1
NVM_DIRS_TO_SEARCH1='' NVM_DIRS_TO_SEARCH1=''
@ -1088,10 +1086,6 @@ nvm_ls() {
-e "s#^${NVM_NODE_PREFIX}-##;" \ -e "s#^${NVM_NODE_PREFIX}-##;" \
)" )"
fi fi
if [ "${ZSH_HAS_SHWORDSPLIT_UNSET}" -eq 1 ] && nvm_has "unsetopt"; then
unsetopt shwordsplit
fi
fi fi
if [ "${NVM_ADD_SYSTEM-}" = true ]; then if [ "${NVM_ADD_SYSTEM-}" = true ]; then
@ -1188,11 +1182,7 @@ nvm_ls_remote_index_tab() {
unset PATTERN unset PATTERN
fi fi
ZSH_HAS_SHWORDSPLIT_UNSET=1 nvm_is_zsh && setopt local_options shwordsplit
if nvm_has "setopt"; then
ZSH_HAS_SHWORDSPLIT_UNSET="$(set +e ; setopt | nvm_grep -q shwordsplit ; nvm_echo $?)"
setopt shwordsplit
fi
local VERSION_LIST local VERSION_LIST
VERSION_LIST="$(nvm_download -L -s "${MIRROR}/index.tab" -o - \ VERSION_LIST="$(nvm_download -L -s "${MIRROR}/index.tab" -o - \
| command sed " | command sed "
@ -1237,9 +1227,6 @@ nvm_ls_remote_index_tab() {
$VERSION_LIST $VERSION_LIST
EOF EOF
)" )"
if [ "$ZSH_HAS_SHWORDSPLIT_UNSET" -eq 1 ] && nvm_has "unsetopt"; then
unsetopt shwordsplit
fi
if [ -z "${VERSIONS}" ]; then if [ -z "${VERSIONS}" ]; then
nvm_echo 'N/A' nvm_echo 'N/A'
return 3 return 3
@ -1509,8 +1496,6 @@ nvm_print_implicit_alias() {
return 2 return 2
fi fi
local ZSH_HAS_SHWORDSPLIT_UNSET
local NVM_IOJS_PREFIX local NVM_IOJS_PREFIX
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)" NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
local NVM_NODE_PREFIX local NVM_NODE_PREFIX
@ -1526,11 +1511,7 @@ nvm_print_implicit_alias() {
NVM_COMMAND="nvm_ls $NVM_IMPLICIT" NVM_COMMAND="nvm_ls $NVM_IMPLICIT"
fi fi
ZSH_HAS_SHWORDSPLIT_UNSET=1 nvm_is_zsh && setopt local_options shwordsplit
if nvm_has "setopt"; then
ZSH_HAS_SHWORDSPLIT_UNSET="$(set +e ; setopt | nvm_grep -q shwordsplit ; nvm_echo $?)"
setopt shwordsplit
fi
local NVM_IOJS_VERSION local NVM_IOJS_VERSION
local EXIT_CODE local EXIT_CODE
@ -1540,10 +1521,6 @@ nvm_print_implicit_alias() {
NVM_IOJS_VERSION="$(nvm_echo "$NVM_IOJS_VERSION" | command sed "s/^$NVM_IMPLICIT-//" | nvm_grep -e '^v' | command cut -c2- | command cut -d . -f 1,2 | uniq | command tail -1)" NVM_IOJS_VERSION="$(nvm_echo "$NVM_IOJS_VERSION" | command sed "s/^$NVM_IMPLICIT-//" | nvm_grep -e '^v' | command cut -c2- | command cut -d . -f 1,2 | uniq | command tail -1)"
fi fi
if [ "$ZSH_HAS_SHWORDSPLIT_UNSET" -eq 1 ] && nvm_has "unsetopt"; then
unsetopt shwordsplit
fi
if [ "_$NVM_IOJS_VERSION" = "_N/A" ]; then if [ "_$NVM_IOJS_VERSION" = "_N/A" ]; then
nvm_echo 'N/A' nvm_echo 'N/A'
else else
@ -1561,17 +1538,9 @@ nvm_print_implicit_alias() {
NVM_COMMAND="nvm_ls node" NVM_COMMAND="nvm_ls node"
fi fi
ZSH_HAS_SHWORDSPLIT_UNSET=1 nvm_is_zsh && setopt local_options shwordsplit
if nvm_has "setopt"; then
ZSH_HAS_SHWORDSPLIT_UNSET="$(set +e ; setopt | nvm_grep -q shwordsplit ; nvm_echo $?)"
setopt shwordsplit
fi
LAST_TWO=$($NVM_COMMAND | nvm_grep -e '^v' | command cut -c2- | command cut -d . -f 1,2 | uniq) LAST_TWO=$($NVM_COMMAND | nvm_grep -e '^v' | command cut -c2- | command cut -d . -f 1,2 | uniq)
if [ "$ZSH_HAS_SHWORDSPLIT_UNSET" -eq 1 ] && nvm_has "unsetopt"; then
unsetopt shwordsplit
fi
;; ;;
esac esac
local MINOR local MINOR
@ -1580,11 +1549,7 @@ nvm_print_implicit_alias() {
local MOD local MOD
local NORMALIZED_VERSION local NORMALIZED_VERSION
ZSH_HAS_SHWORDSPLIT_UNSET=1 nvm_is_zsh && setopt local_options shwordsplit
if nvm_has "setopt"; then
ZSH_HAS_SHWORDSPLIT_UNSET="$(set +e ; setopt | nvm_grep -q shwordsplit ; nvm_echo $?)"
setopt shwordsplit
fi
for MINOR in $LAST_TWO; do for MINOR in $LAST_TWO; do
NORMALIZED_VERSION="$(nvm_normalize_version "$MINOR")" NORMALIZED_VERSION="$(nvm_normalize_version "$MINOR")"
if [ "_0${NORMALIZED_VERSION#?}" != "_$NORMALIZED_VERSION" ]; then if [ "_0${NORMALIZED_VERSION#?}" != "_$NORMALIZED_VERSION" ]; then
@ -1598,9 +1563,6 @@ nvm_print_implicit_alias() {
fi fi
fi fi
done done
if [ "$ZSH_HAS_SHWORDSPLIT_UNSET" -eq 1 ] && nvm_has "unsetopt"; then
unsetopt shwordsplit
fi
if [ "_$2" = '_stable' ]; then if [ "_$2" = '_stable' ]; then
nvm_echo "${STABLE}" nvm_echo "${STABLE}"
@ -2077,12 +2039,7 @@ nvm_install_source() {
PROGRESS_BAR="--progress-bar" PROGRESS_BAR="--progress-bar"
fi fi
local ZSH_HAS_SHWORDSPLIT_UNSET nvm_is_zsh && setopt local_options shwordsplit
ZSH_HAS_SHWORDSPLIT_UNSET=1
if nvm_has "setopt"; then
ZSH_HAS_SHWORDSPLIT_UNSET="$(set +e ; setopt | nvm_grep -q shwordsplit ; nvm_echo $?)"
setopt shwordsplit
fi
TARBALL="$(PROGRESS_BAR="${PROGRESS_BAR}" nvm_download_artifact "${FLAVOR}" source "${TYPE}" "${VERSION}" | command tail -1)" && \ TARBALL="$(PROGRESS_BAR="${PROGRESS_BAR}" nvm_download_artifact "${FLAVOR}" source "${TYPE}" "${VERSION}" | command tail -1)" && \
[ -f "${TARBALL}" ] && \ [ -f "${TARBALL}" ] && \
@ -2099,16 +2056,10 @@ nvm_install_source() {
command rm -f "${VERSION_PATH}" 2>/dev/null && \ command rm -f "${VERSION_PATH}" 2>/dev/null && \
$make -j "${NVM_MAKE_JOBS}" ${MAKE_CXX-} install $make -j "${NVM_MAKE_JOBS}" ${MAKE_CXX-} install
); then ); then
if [ "$ZSH_HAS_SHWORDSPLIT_UNSET" -eq 1 ] && nvm_has "unsetopt"; then
unsetopt shwordsplit
fi
nvm_err "nvm: install ${VERSION} failed!" nvm_err "nvm: install ${VERSION} failed!"
command rm -rf "${TMPDIR-}" command rm -rf "${TMPDIR-}"
return 1 return 1
fi fi
if [ "$ZSH_HAS_SHWORDSPLIT_UNSET" -eq 1 ] && nvm_has "unsetopt"; then
unsetopt shwordsplit
fi
} }
nvm_use_if_needed() { nvm_use_if_needed() {
@ -2317,31 +2268,17 @@ nvm_is_natural_num() {
# Check version dir permissions # Check version dir permissions
nvm_check_file_permissions() { nvm_check_file_permissions() {
local ZSH_HAS_NONOMATCH_UNSET nvm_is_zsh && setopt local_options nonomatch
ZSH_HAS_NONOMATCH_UNSET=1
if nvm_has "setopt"; then
ZSH_HAS_NONOMATCH_UNSET="$(set +e ; setopt | nvm_grep -q nonomatch ; nvm_echo $?)"
setopt nonomatch
fi
for FILE in "$1"/* "$1"/.[!.]* "$1"/..?* ; do for FILE in "$1"/* "$1"/.[!.]* "$1"/..?* ; do
if [ -d "$FILE" ]; then if [ -d "$FILE" ]; then
if ! nvm_check_file_permissions "$FILE"; then if ! nvm_check_file_permissions "$FILE"; then
if [ "${ZSH_HAS_NONOMATCH_UNSET}" -eq 1 ] && nvm_has "setopt"; then
setopt nomatch
fi
return 2 return 2
fi fi
elif [ -e "$FILE" ] && [ ! -w "$FILE" ] && [ ! -O "$FILE" ]; then elif [ -e "$FILE" ] && [ ! -w "$FILE" ] && [ ! -O "$FILE" ]; then
nvm_err "file is not writable or self-owned: $(nvm_sanitize_path "$FILE")" nvm_err "file is not writable or self-owned: $(nvm_sanitize_path "$FILE")"
if [ "${ZSH_HAS_NONOMATCH_UNSET}" -eq 1 ] && nvm_has "setopt"; then
setopt nomatch
fi
return 1 return 1
fi fi
done done
if [ "${ZSH_HAS_NONOMATCH_UNSET}" -eq 1 ] && nvm_has "setopt"; then
setopt nomatch
fi
return 0 return 0
} }
@ -2466,13 +2403,8 @@ nvm() {
;; ;;
"debug" ) "debug" )
local ZSH_HAS_SHWORDSPLIT_UNSET
local OS_VERSION local OS_VERSION
ZSH_HAS_SHWORDSPLIT_UNSET=1 nvm_is_zsh && setopt local_options shwordsplit
if nvm_has "setopt"; then
ZSH_HAS_SHWORDSPLIT_UNSET="$(set +e ; setopt | nvm_grep -q shwordsplit ; nvm_echo $?)"
setopt shwordsplit
fi
nvm_err "nvm --version: v$(nvm --version)" nvm_err "nvm --version: v$(nvm --version)"
if [ -n "${TERM_PROGRAM-}" ]; then if [ -n "${TERM_PROGRAM-}" ]; then
nvm_err "\$TERM_PROGRAM: $TERM_PROGRAM" nvm_err "\$TERM_PROGRAM: $TERM_PROGRAM"
@ -2526,9 +2458,6 @@ nvm() {
NVM_DEBUG_OUTPUT="$($NVM_DEBUG_COMMAND 2>&1)" NVM_DEBUG_OUTPUT="$($NVM_DEBUG_COMMAND 2>&1)"
nvm_err "$NVM_DEBUG_COMMAND: $(nvm_sanitize_path "$NVM_DEBUG_OUTPUT")" nvm_err "$NVM_DEBUG_COMMAND: $(nvm_sanitize_path "$NVM_DEBUG_OUTPUT")"
done done
if [ "$ZSH_HAS_SHWORDSPLIT_UNSET" -eq 1 ] && nvm_has "unsetopt"; then
unsetopt shwordsplit
fi
return 42 return 42
;; ;;
@ -3115,12 +3044,7 @@ nvm() {
local EXIT_CODE local EXIT_CODE
local ZSH_HAS_SHWORDSPLIT_UNSET nvm_is_zsh && setopt local_options shwordsplit
ZSH_HAS_SHWORDSPLIT_UNSET=1
if nvm_has "setopt"; then
ZSH_HAS_SHWORDSPLIT_UNSET="$(set +e ; setopt | nvm_grep -q shwordsplit ; nvm_echo $?)"
setopt shwordsplit
fi
local LTS_ARG local LTS_ARG
if [ -n "${NVM_LTS-}" ]; then if [ -n "${NVM_LTS-}" ]; then
LTS_ARG="--lts=${NVM_LTS-}" LTS_ARG="--lts=${NVM_LTS-}"
@ -3134,9 +3058,6 @@ nvm() {
nvm exec "${NVM_SILENT-}" "${LTS_ARG-}" "$VERSION" node "$@" nvm exec "${NVM_SILENT-}" "${LTS_ARG-}" "$VERSION" node "$@"
fi fi
EXIT_CODE="$?" EXIT_CODE="$?"
if [ "$ZSH_HAS_SHWORDSPLIT_UNSET" -eq 1 ] && nvm_has "unsetopt"; then
unsetopt shwordsplit
fi
return $EXIT_CODE return $EXIT_CODE
;; ;;
"exec" ) "exec" )
@ -3549,7 +3470,7 @@ nvm() {
nvm_print_default_alias nvm_print_formatted_alias nvm_resolve_local_alias \ nvm_print_default_alias nvm_print_formatted_alias nvm_resolve_local_alias \
nvm_sanitize_path nvm_has_colors nvm_process_parameters \ nvm_sanitize_path nvm_has_colors nvm_process_parameters \
node_version_has_solaris_binary iojs_version_has_solaris_binary \ node_version_has_solaris_binary iojs_version_has_solaris_binary \
nvm_curl_libz_support nvm_command_info \ nvm_curl_libz_support nvm_command_info nvm_is_zsh \
> /dev/null 2>&1 > /dev/null 2>&1
unset NVM_RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_IOJS_ORG_MIRROR NVM_DIR \ unset NVM_RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_IOJS_ORG_MIRROR NVM_DIR \
NVM_CD_FLAGS NVM_BIN NVM_MAKE_JOBS \ NVM_CD_FLAGS NVM_BIN NVM_MAKE_JOBS \