[Fix] `nvm_die_on_prefix`: avoid grepping env functions in bash

ironically, nvm itself has functions that matched this grep.
Jordan Harband 2021-09-08 23:49:16 -07:00
parent f03f69508e
commit 2dad0455ec
No known key found for this signature in database
GPG Key ID: 9F6A681E35EF8B56
1 changed files with 10 additions and 6 deletions

16
nvm.sh
View File

@ -2456,18 +2456,22 @@ nvm_die_on_prefix() {
#
# here, we avoid trying to replicate "which one wins" or testing the value; if any are defined, it errors
# until none are left.
local NVM_NPM_CONFIG_PREFIX_ENV
NVM_NPM_CONFIG_PREFIX_ENV="$(command env | nvm_grep -i NPM_CONFIG_PREFIX | command tail -1 | command awk -F '=' '{print $1}')"
if [ -n "${NVM_NPM_CONFIG_PREFIX_ENV-}" ]; then
local NVM_NPM_CONFIG_x_PREFIX_ENV
if [ -n "${BASH_SOURCE-}" ]; then
NVM_NPM_CONFIG_x_PREFIX_ENV="$(command set | command awk -F '=' '! /^[0-9A-Z_a-z]+=/ {exit} {print $1}' | nvm_grep -i NPM_CONFIG_PREFIX | command tail -1)"
else
NVM_NPM_CONFIG_x_PREFIX_ENV="$(command env | nvm_grep -i NPM_CONFIG_PREFIX | command tail -1 | command awk -F '=' '{print $1}')"
fi
if [ -n "${NVM_NPM_CONFIG_x_PREFIX_ENV-}" ]; then
local NVM_CONFIG_VALUE
eval "NVM_CONFIG_VALUE=\"\$${NVM_NPM_CONFIG_PREFIX_ENV}\""
eval "NVM_CONFIG_VALUE=\"\$${NVM_NPM_CONFIG_x_PREFIX_ENV}\""
if [ -n "${NVM_CONFIG_VALUE-}" ] && [ "_${NVM_OS}" = "_win" ]; then
NVM_CONFIG_VALUE="$(cd "$NVM_CONFIG_VALUE" 2>/dev/null && pwd)"
fi
if [ -n "${NVM_CONFIG_VALUE-}" ] && ! nvm_tree_contains_path "${NVM_DIR}" "${NVM_CONFIG_VALUE}"; then
nvm deactivate >/dev/null 2>&1
nvm_err "nvm is not compatible with the \"${NVM_NPM_CONFIG_PREFIX_ENV}\" environment variable: currently set to \"${NVM_CONFIG_VALUE}\""
nvm_err "Run \`unset ${NVM_NPM_CONFIG_PREFIX_ENV}\` to unset it."
nvm_err "nvm is not compatible with the \"${NVM_NPM_CONFIG_x_PREFIX_ENV}\" environment variable: currently set to \"${NVM_CONFIG_VALUE}\""
nvm_err "Run \`unset ${NVM_NPM_CONFIG_x_PREFIX_ENV}\` to unset it."
return 4
fi
fi