`nvm debug`: Improve OS version detection

Peter Dave Hello 2018-02-24 02:53:40 +08:00 committed by Jordan Harband
parent 8ff437ae51
commit ca66a13710
No known key found for this signature in database
GPG Key ID: 64A196AEE0916D55
1 changed files with 10 additions and 2 deletions

12
nvm.sh
View File

@ -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)"