From ca66a13710070e1e3077aafe96ef12914ea9567b Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Sat, 24 Feb 2018 02:53:40 +0800 Subject: [PATCH] `nvm debug`: Improve OS version detection --- nvm.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/nvm.sh b/nvm.sh index 925f574..7aebd35 100644 --- a/nvm.sh +++ b/nvm.sh @@ -2383,6 +2383,7 @@ nvm() { "debug" ) local ZSH_HAS_SHWORDSPLIT_UNSET + local OS_VERSION ZSH_HAS_SHWORDSPLIT_UNSET=1 if nvm_has "setopt"; then ZSH_HAS_SHWORDSPLIT_UNSET="$(set +e ; setopt | nvm_grep -q shwordsplit ; nvm_echo $?)" @@ -2405,9 +2406,16 @@ nvm() { nvm_err "shell version: '$(${SHELL} --version | command head -n 1)'" nvm_err "uname -a: '$(command uname -a | command awk '{$2=""; print}' | command xargs)'" if [ "$(nvm_get_os)" = "darwin" ] && nvm_has sw_vers; then - nvm_err "OS version: $(sw_vers | command awk '{print $2}' | command xargs)" + OS_VERSION="$(sw_vers | command awk '{print $2}' | command xargs)" elif [ -r "/etc/issue" ]; then - nvm_err "OS version: $(command head -n 1 /etc/issue | command sed 's/\\.//g')" + OS_VERSION="$(command head -n 1 /etc/issue | command sed 's/\\.//g')" + if [ -z "${OS_VERSION}" ] && [ -r "/etc/os-release" ] ; then + # shellcheck disable=SC1091 + OS_VERSION="$(. /etc/os-release && echo "${NAME}" "${VERSION}")" + fi + fi + if [ -n "${OS_VERSION}" ]; then + nvm_err "OS version: ${OS_VERSION}" fi if nvm_has "curl"; then nvm_err "curl: $(nvm_command_info curl), $(command curl -V | command head -n 1)"